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"
|
|
|
|
)
|
|
|
|
|
|
|
|
type config struct {
|
|
|
|
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-10-05 23:18:02 +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")
|
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
|
|
|
|
|
|
|
conf := config{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-10-05 23:18:02 +02:00
|
|
|
return conf
|
2023-10-02 15:03:04 +02:00
|
|
|
}
|