89 lines
1.9 KiB
Go
89 lines
1.9 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
|
|
gocnjhelper "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper"
|
|
"github.com/joho/godotenv"
|
|
)
|
|
|
|
var Cfg Config
|
|
|
|
type Config struct {
|
|
ServiceName uint8
|
|
ServiceType uint8
|
|
Debug bool
|
|
Host string
|
|
Port string
|
|
StoragePath string
|
|
StorageUrlAddress string
|
|
ScyllaDB ScyllaDB
|
|
RabbitMq RabbitMq
|
|
}
|
|
|
|
type ScyllaDB struct {
|
|
Host string
|
|
Username string
|
|
Password string
|
|
Keyspace string
|
|
}
|
|
|
|
type RabbitMq struct {
|
|
Host string
|
|
Username string
|
|
Password string
|
|
}
|
|
|
|
func LoadConfig() {
|
|
// argument to start the server locally for development
|
|
if len(os.Args) > 1 {
|
|
if os.Args[1] == "--local" || os.Args[1] == "-l" {
|
|
if err := godotenv.Load("local.env"); err != nil {
|
|
gocnjhelper.LogFatalf("Failed to load env, err: %s", err)
|
|
}
|
|
}
|
|
}
|
|
|
|
debug, err := strconv.ParseBool(os.Getenv("DEBUG"))
|
|
|
|
if err != nil {
|
|
gocnjhelper.LogFatalf("Failed to parse boolean, err: %s", err)
|
|
}
|
|
|
|
serviceName, err := strconv.Atoi(os.Getenv("SERVICE_NAME"))
|
|
|
|
if err != nil {
|
|
gocnjhelper.LogFatalf("Failed to parse int, err: %s", err)
|
|
}
|
|
|
|
serviceType, err := strconv.Atoi(os.Getenv("SERVICE_TYPE"))
|
|
|
|
if err != nil {
|
|
gocnjhelper.LogFatalf("Failed to parse int, err: %s", err)
|
|
}
|
|
|
|
cfg := Config{
|
|
ServiceName: uint8(serviceName),
|
|
ServiceType: uint8(serviceType),
|
|
Debug: debug,
|
|
Host: os.Getenv("HOST"),
|
|
Port: os.Getenv("PORT"),
|
|
StoragePath: os.Getenv("STORAGE_PATH"),
|
|
StorageUrlAddress: os.Getenv("STORAGE_URL_ADDRESS"),
|
|
ScyllaDB: ScyllaDB{
|
|
Host: os.Getenv("SCYLLADB_HOST"),
|
|
Username: os.Getenv("SCYLLADB_USERNAME"),
|
|
Password: os.Getenv("SCYLLADB_PASSWORD"),
|
|
Keyspace: os.Getenv("SCYLLADB_KEYSPACE"),
|
|
},
|
|
RabbitMq: RabbitMq{
|
|
Host: os.Getenv("RABBITMQ_HOST"),
|
|
Username: os.Getenv("RABBITMQ_USERNAME"),
|
|
Password: os.Getenv("RABBITMQ_PASSWORD"),
|
|
},
|
|
}
|
|
|
|
Cfg = cfg
|
|
}
|