2022-08-13 23:33:50 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"os"
|
2022-08-14 23:51:32 +02:00
|
|
|
"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 {
|
2022-08-14 23:51:32 +02:00
|
|
|
port, err := strconv.Atoi(os.Getenv("PORT"))
|
2022-08-13 23:33:50 +02:00
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-14 23:51:32 +02:00
|
|
|
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",
|
2022-08-14 23:51:32 +02:00
|
|
|
AuthUsername: os.Getenv("AUTH_USERNAME"),
|
|
|
|
|
AuthPassword: os.Getenv("AUTH_PASSWORD"),
|
2022-08-21 22:48:18 +02:00
|
|
|
AuthKey: os.Getenv("AUTH_KEY"),
|
2022-08-13 23:33:50 +02:00
|
|
|
}
|
|
|
|
|
|
2022-08-21 22:48:18 +02:00
|
|
|
// TODO: Crash when any auth* param is empty
|
|
|
|
|
|
2022-08-13 23:33:50 +02:00
|
|
|
return &config
|
|
|
|
|
}
|