graphicek/server/config/config.go

41 lines
752 B
Go
Raw Normal View History

2022-08-13 23:33:50 +02:00
package config
import (
"os"
"strconv"
2022-08-13 23:33:50 +02:00
)
type Config struct {
2022-08-21 20:51:14 +02:00
Mode string
DatabaseUrl string
Port int
Ip string
2024-03-31 18:33:56 +02:00
AuthEnabled bool
2022-08-21 20:51:14 +02:00
AuthUsername string
AuthPassword string
AuthKey string
2022-08-13 23:33:50 +02:00
}
func LoadConfig() *Config {
port, err := strconv.Atoi(os.Getenv("PORT"))
2022-08-13 23:33:50 +02:00
if err != nil {
panic(err)
}
config := Config{
Mode: os.Getenv("GIN_MODE"),
DatabaseUrl: os.Getenv("DATABASE_URL"),
Port: port,
Ip: os.Getenv("BIND_IP"),
2024-03-31 18:33:56 +02:00
AuthEnabled: os.Getenv("AUTH_ENABLED") != "false",
AuthUsername: os.Getenv("AUTH_USERNAME"),
AuthPassword: os.Getenv("AUTH_PASSWORD"),
AuthKey: os.Getenv("AUTH_KEY"),
2022-08-13 23:33:50 +02:00
}
// TODO: Crash when any auth* param is empty
2022-08-13 23:33:50 +02:00
return &config
}