mirror of
https://codeberg.org/video-prize-ranch/rimgo.git
synced 2026-01-28 17:41:13 +00:00
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
package utils
|
|
|
|
import (
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
type config struct {
|
|
Port string
|
|
Addr string
|
|
ImgurId string
|
|
ProtocolDetection bool
|
|
Secure bool
|
|
ForceWebp bool
|
|
ImageCache bool
|
|
CleanupInterval time.Duration
|
|
CacheDir string
|
|
Privacy map[string]interface{}
|
|
}
|
|
|
|
var Config config
|
|
|
|
func envString(name, def string) string {
|
|
env := os.Getenv(name)
|
|
if env != "" {
|
|
return env
|
|
}
|
|
return def
|
|
}
|
|
func envBool(name string) bool {
|
|
return os.Getenv(name) == "true" || os.Getenv(name) == "1"
|
|
}
|
|
|
|
func LoadConfig() {
|
|
Config = config{
|
|
Port: envString("PORT", "3000"),
|
|
Addr: envString("ADDR", "0.0.0.0"),
|
|
ImgurId: envString("IMGUR_CLIENT_ID", "546c25a59c58ad7"),
|
|
ProtocolDetection: envBool("PROTOCOL_DETECTION"),
|
|
Secure: envBool("SECURE"),
|
|
ForceWebp: envBool("FORCE_WEBP"),
|
|
Privacy: map[string]interface{}{
|
|
"set": os.Getenv("PRIVACY_NOT_COLLECTED") != "",
|
|
"policy": os.Getenv("PRIVACY_POLICY"),
|
|
"message": os.Getenv("PRIVACY_MESSAGE"),
|
|
"country": os.Getenv("PRIVACY_COUNTRY"),
|
|
"provider": os.Getenv("PRIVACY_PROVIDER"),
|
|
"cloudflare": envBool("PRIVACY_CLOUDFLARE"),
|
|
"not_collected": envBool("PRIVACY_NOT_COLLECTED"),
|
|
"ip": envBool("PRIVACY_IP"),
|
|
"url": envBool("PRIVACY_URL"),
|
|
"device": envBool("PRIVACY_DEVICE"),
|
|
"diagnostics": envBool("PRIVACY_DIAGNOSTICS"),
|
|
},
|
|
}
|
|
}
|