2022-04-22 17:38:40 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/pkg/list"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Environment names.
|
|
|
|
const (
|
2022-04-22 18:24:59 +02:00
|
|
|
EnvUnsafe = "unsafe"
|
2022-04-22 17:38:40 +02:00
|
|
|
EnvDebug = "debug"
|
|
|
|
EnvTrace = "trace"
|
|
|
|
EnvDemo = "demo"
|
|
|
|
EnvSponsor = "sponsor"
|
|
|
|
EnvTest = "test"
|
|
|
|
)
|
|
|
|
|
2023-03-15 17:05:05 +01:00
|
|
|
// EnvVar returns the name of the environment variable for the specified config flag.
|
|
|
|
func EnvVar(flag string) string {
|
|
|
|
return "PHOTOPRISM_" + strings.ToUpper(strings.ReplaceAll(flag, "-", "_"))
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:38:40 +02:00
|
|
|
// Env checks the presence of environment and command-line flags.
|
|
|
|
func Env(vars ...string) bool {
|
|
|
|
for _, s := range vars {
|
2023-03-15 17:05:05 +01:00
|
|
|
if os.Getenv(EnvVar(s)) == "true" || list.Contains(os.Args, "--"+s) {
|
2022-04-22 17:38:40 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|