2023-10-02 15:03:04 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-10-05 23:18:02 +02:00
|
|
|
"github.com/joho/godotenv"
|
|
|
|
"log"
|
2023-10-02 15:03:04 +02:00
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
2023-11-26 00:00:53 +01:00
|
|
|
type Config struct {
|
2023-10-02 15:03:04 +02:00
|
|
|
host string
|
|
|
|
port string
|
|
|
|
redisAddr string
|
|
|
|
redisUser string
|
|
|
|
redisPassword string
|
|
|
|
redisDB int
|
2023-10-02 19:22:56 +02:00
|
|
|
urlLength int
|
2023-10-02 15:03:04 +02:00
|
|
|
}
|
|
|
|
|
2023-11-26 00:00:53 +01:00
|
|
|
func GetConfig() Config {
|
2023-10-05 23:18:02 +02:00
|
|
|
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")
|
2023-10-05 23:18:02 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-10-05 23:18:02 +02:00
|
|
|
redisDB, err := strconv.Atoi(db)
|
2023-10-02 15:03:04 +02:00
|
|
|
if err != nil {
|
2023-10-05 23:18:02 +02:00
|
|
|
log.Fatal("Invalid PLAKKEN_REDIS_DB")
|
2023-10-02 15:03:04 +02:00
|
|
|
}
|
|
|
|
|
2023-10-05 23:18:02 +02:00
|
|
|
urlLen, err := strconv.Atoi(uLen)
|
2023-10-02 19:22:56 +02:00
|
|
|
if err != nil {
|
2023-10-05 23:18:02 +02:00
|
|
|
log.Fatal("Invalid PLAKKEN_REDIS_URL_LEN")
|
2023-10-02 19:22:56 +02:00
|
|
|
}
|
2023-10-05 23:18:02 +02:00
|
|
|
|
2023-11-26 00:00:53 +01:00
|
|
|
return Config{
|
2023-10-05 23:18:02 +02:00
|
|
|
host: os.Getenv("PLAKKEN_INTERFACE"),
|
2023-10-02 15:03:04 +02:00
|
|
|
port: port,
|
|
|
|
redisAddr: redisAddr,
|
2023-10-05 23:18:02 +02:00
|
|
|
redisUser: os.Getenv("PLAKKEN_REDIS_USER"),
|
|
|
|
redisPassword: os.Getenv("PLAKKEN_REDIS_PASSWORD"),
|
2023-10-02 15:03:04 +02:00
|
|
|
redisDB: redisDB,
|
2023-10-05 23:18:02 +02:00
|
|
|
urlLength: urlLen,
|
2023-10-02 15:03:04 +02:00
|
|
|
}
|
|
|
|
}
|