-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.go
44 lines (38 loc) · 1.13 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package pobj
import (
"log/slog"
"os"
"github.com/picosh/pobj/storage"
)
func GetEnv(key string, defaultVal string) string {
if value, exists := os.LookupEnv(key); exists {
return value
}
return defaultVal
}
func EnvDriverDetector(logger *slog.Logger) (storage.ObjectStorage, error) {
driver := GetEnv("OBJECT_DRIVER", "fs")
logger.Info("driver detected", "driver", driver)
if driver == "memory" {
return storage.NewStorageMemory(map[string]map[string]string{})
} else if driver == "minio" {
url := GetEnv("MINIO_URL", "")
user := GetEnv("MINIO_ROOT_USER", "")
pass := GetEnv("MINIO_ROOT_PASSWORD", "")
logger.Info(
"object config detected",
"url", url,
"user", user,
)
return storage.NewStorageMinio(url, user, pass)
} else if driver == "s3" {
region := GetEnv("AWS_REGION", "us-east-1")
key := GetEnv("AWS_ACCESS_KEY_ID", "")
secret := GetEnv("AWS_SECRET_ACCESS_KEY", "")
return storage.NewStorageS3(region, key, secret)
}
// implied driver == "fs"
storageDir := GetEnv("OBJECT_URL", "./.storage")
logger.Info("object config detected", "dir", storageDir)
return storage.NewStorageFS(storageDir)
}