This repository has been archived on 2023-11-13. You can view files and clone it, but cannot push or open issues or pull requests.
imagini/internal/config/config.go

35 lines
878 B
Go
Raw Normal View History

2021-01-06 19:36:09 +00:00
package config
import (
2021-01-08 02:45:59 +00:00
"os"
2021-01-06 19:36:09 +00:00
)
2021-01-08 02:45:59 +00:00
type Config struct {
DBType string
DBName string
DBPassword string
DataPath string
ConfigPath string
JWTSecret string
2021-01-12 04:48:32 +00:00
ListenPort string
2021-01-08 02:45:59 +00:00
}
func NewConfig() *Config {
return &Config{
DBType: getEnv("DATABASE_TYPE", "SQLite"),
DBName: getEnv("DATABASE_NAME", "imagini"),
DBPassword: getEnv("DATABASE_PASSWORD", ""),
ConfigPath: getEnv("CONFIG_PATH", "/config"),
DataPath: getEnv("DATA_PATH", "/data"),
JWTSecret: getEnv("JWT_SECRET", "58b9340c0472cf045db226bc445966524e780cd38bc3dd707afce80c95d4de6f"),
2021-01-12 04:48:32 +00:00
ListenPort: getEnv("LISTEN_PORT", "8484"),
2021-01-08 02:45:59 +00:00
}
2021-01-06 19:36:09 +00:00
}
2021-01-08 02:45:59 +00:00
func getEnv(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
2021-01-06 19:36:09 +00:00
}
2021-01-08 02:45:59 +00:00
return fallback
2021-01-06 19:36:09 +00:00
}