2021-01-17 16:50:48 +01:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import "os"
|
|
|
|
|
|
|
|
// EnvironmentVariable represents the name of an environment variable used to configure Photoview
|
|
|
|
type EnvironmentVariable string
|
|
|
|
|
|
|
|
// General options
|
|
|
|
const (
|
|
|
|
EnvDevelopmentMode EnvironmentVariable = "PHOTOVIEW_DEVELOPMENT_MODE"
|
|
|
|
EnvServeUI EnvironmentVariable = "PHOTOVIEW_SERVE_UI"
|
2021-02-26 15:10:28 +01:00
|
|
|
EnvUIPath EnvironmentVariable = "PHOTOVIEW_UI_PATH"
|
2021-01-17 16:50:48 +01:00
|
|
|
EnvMediaCachePath EnvironmentVariable = "PHOTOVIEW_MEDIA_CACHE"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Network related
|
|
|
|
const (
|
|
|
|
EnvListenIP EnvironmentVariable = "PHOTOVIEW_LISTEN_IP"
|
|
|
|
EnvListenPort EnvironmentVariable = "PHOTOVIEW_LISTEN_PORT"
|
|
|
|
EnvAPIEndpoint EnvironmentVariable = "PHOTOVIEW_API_ENDPOINT"
|
|
|
|
EnvUIEndpoint EnvironmentVariable = "PHOTOVIEW_UI_ENDPOINT"
|
|
|
|
EnvPublicEndpoint EnvironmentVariable = "PHOTOVIEW_PUBLIC_ENDPOINT"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Database related
|
|
|
|
const (
|
|
|
|
EnvDatabaseDriver EnvironmentVariable = "PHOTOVIEW_DATABASE_DRIVER"
|
|
|
|
EnvMysqlURL EnvironmentVariable = "PHOTOVIEW_MYSQL_URL"
|
2021-01-31 17:06:25 +01:00
|
|
|
EnvPostgresURL EnvironmentVariable = "PHOTOVIEW_POSTGRES_URL"
|
2021-01-17 16:50:48 +01:00
|
|
|
EnvSqlitePath EnvironmentVariable = "PHOTOVIEW_SQLITE_PATH"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetName returns the name of the environment variable itself
|
|
|
|
func (v EnvironmentVariable) GetName() string {
|
|
|
|
return string(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetValue returns the value of the environment
|
|
|
|
func (v EnvironmentVariable) GetValue() string {
|
|
|
|
return os.Getenv(string(v))
|
|
|
|
}
|
|
|
|
|
|
|
|
// ShouldServeUI whether or not the "serve ui" option is enabled
|
|
|
|
func ShouldServeUI() bool {
|
|
|
|
return EnvServeUI.GetValue() == "1"
|
|
|
|
}
|
|
|
|
|
|
|
|
// DevelopmentMode describes whether or not the server is running in development mode,
|
|
|
|
// and should thus print debug informations and enable other features related to developing.
|
|
|
|
func DevelopmentMode() bool {
|
|
|
|
return EnvDevelopmentMode.GetValue() == "1"
|
|
|
|
}
|
2021-02-26 15:10:28 +01:00
|
|
|
|
|
|
|
// UIPath returns the value from where the static UI files are located if SERVE_UI=1
|
|
|
|
func UIPath() string {
|
|
|
|
if path := EnvUIPath.GetValue(); path != "" {
|
|
|
|
return path
|
|
|
|
}
|
|
|
|
|
|
|
|
return "./ui"
|
|
|
|
}
|