plakken/config.go

55 lines
1.1 KiB
Go
Raw Normal View History

2023-10-02 15:03:04 +02:00
package main
import (
"github.com/joho/godotenv"
"log"
2023-10-02 15:03:04 +02:00
"os"
"strconv"
)
type Config struct {
2023-10-02 15:03:04 +02:00
host string
port string
redisAddr string
redisUser string
redisPassword string
redisDB int
urlLength int
2023-10-02 15:03:04 +02:00
}
func GetConfig() Config {
err := godotenv.Load()
if err != nil {
log.Fatalf("Error loading .env file: %v", err)
}
2023-10-02 15:03:04 +02:00
port := os.Getenv("PLAKKEN_PORT")
redisAddr := os.Getenv("PLAKKEN_REDIS_ADDR")
db := os.Getenv("PLAKKEN_REDIS_DB")
uLen := os.Getenv("PLAKKEN_REDIS_URL_LEN")
if port == "" || redisAddr == "" {
log.Fatal("Missing or invalid PLAKKEN_PORT or PLAKKEN_REDIS_ADDR")
2023-10-02 15:03:04 +02:00
}
redisDB, err := strconv.Atoi(db)
2023-10-02 15:03:04 +02:00
if err != nil {
log.Fatal("Invalid PLAKKEN_REDIS_DB")
2023-10-02 15:03:04 +02:00
}
urlLen, err := strconv.Atoi(uLen)
if err != nil {
log.Fatal("Invalid PLAKKEN_REDIS_URL_LEN")
}
return Config{
host: os.Getenv("PLAKKEN_INTERFACE"),
2023-10-02 15:03:04 +02:00
port: port,
redisAddr: redisAddr,
redisUser: os.Getenv("PLAKKEN_REDIS_USER"),
redisPassword: os.Getenv("PLAKKEN_REDIS_PASSWORD"),
2023-10-02 15:03:04 +02:00
redisDB: redisDB,
urlLength: urlLen,
2023-10-02 15:03:04 +02:00
}
}