Automatically select s3 backend storage if S3_xxx env are presents
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
a2903b73a0
commit
ecda17fc7d
@ -31,8 +31,12 @@ var (
|
||||
func init() {
|
||||
existing_backends = append(existing_backends, "s3")
|
||||
|
||||
s3_endpoint, _ = os.LookupEnv("S3_ENDPOINT")
|
||||
if endpoint, ok := os.LookupEnv("S3_ENDPOINT"); ok {
|
||||
backend = "s3"
|
||||
s3_endpoint = endpoint
|
||||
}
|
||||
if region, ok := os.LookupEnv("S3_REGION"); ok {
|
||||
backend = "s3"
|
||||
s3_region = region
|
||||
}
|
||||
s3_bucket, _ = os.LookupEnv("S3_BUCKET")
|
||||
|
15
main.go
15
main.go
@ -11,7 +11,10 @@ import (
|
||||
|
||||
var mux = http.NewServeMux()
|
||||
|
||||
var ThumbsDir string
|
||||
var (
|
||||
ThumbsDir string
|
||||
backend = "local"
|
||||
)
|
||||
|
||||
func main() {
|
||||
bind := flag.String("bind", ":8080", "Bind port/socket")
|
||||
@ -19,7 +22,7 @@ func main() {
|
||||
publishedImgDir := flag.String("publishedimgdir", "published/", "Directory where save published pictures")
|
||||
nextImgDir := flag.String("nextimgdir", "next/", "Directory where save pictures to review")
|
||||
baseDir := flag.String("basedir", "images/", "Local base directory where find published and next dirs")
|
||||
backend := flag.String("storage-backend", "local", fmt.Sprintf("Storage backend to use (between: %s)", existing_backends))
|
||||
flag.StringVar(&backend, "storage-backend", backend, fmt.Sprintf("Storage backend to use (between: %s)", existing_backends))
|
||||
flag.StringVar(&ThumbsDir, "thumbsdir", "./images/thumbs/", "Directory where generate thumbs")
|
||||
flag.Parse()
|
||||
|
||||
@ -56,7 +59,7 @@ func main() {
|
||||
})
|
||||
|
||||
var storage_backend FileBackend
|
||||
if backend == nil || *backend == "local" {
|
||||
if backend == "local" {
|
||||
storage_backend = &LocalFileBackend{*baseDir}
|
||||
if _, err := os.Stat(path.Join(*baseDir, *publishedImgDir)); os.IsNotExist(err) {
|
||||
if err := os.MkdirAll(path.Join(*baseDir, *publishedImgDir), 0755); err != nil {
|
||||
@ -68,12 +71,12 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
} else if *backend == "s3" {
|
||||
} else if backend == "s3" {
|
||||
storage_backend = &S3FileBackend{s3_endpoint, s3_region, s3_bucket, s3_access_key, s3_secret_key, s3_path_style, *baseDir}
|
||||
} else {
|
||||
log.Fatalf("%q is not a valid storage backend.", *backend)
|
||||
log.Fatalf("%q is not a valid storage backend.", backend)
|
||||
}
|
||||
log.Printf("Using %s storage backend", *backend)
|
||||
log.Printf("Using %s storage backend", backend)
|
||||
|
||||
pe := &PictureExplorer{
|
||||
FileBackend: storage_backend,
|
||||
|
Loading…
Reference in New Issue
Block a user