96 lines
2.0 KiB
Go
96 lines
2.0 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
|
|
gocnjhelper "git.ex.umbach.dev/ClickandJoin/go-cnj-helper"
|
|
"github.com/joho/godotenv"
|
|
)
|
|
|
|
var Cfg Config
|
|
|
|
type Config struct {
|
|
ServiceName uint8
|
|
ServiceType uint8
|
|
Debug bool
|
|
DefaultLanguageCode string
|
|
RabbitMq RabbitMq
|
|
Mail Mail
|
|
Templates Templates
|
|
}
|
|
|
|
type RabbitMq struct {
|
|
Host string
|
|
Username string
|
|
Password string
|
|
}
|
|
|
|
type Mail struct {
|
|
Host string
|
|
Username string
|
|
Password string
|
|
Port string
|
|
FromName string
|
|
FromEmail string
|
|
}
|
|
|
|
type Templates struct {
|
|
FolderPath string `yaml:"folderPath"`
|
|
ConfigPath string `yaml:"configPath"`
|
|
}
|
|
|
|
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,
|
|
RabbitMq: RabbitMq{
|
|
Host: os.Getenv("RABBITMQ_HOST"),
|
|
Username: os.Getenv("RABBITMQ_USERNAME"),
|
|
Password: os.Getenv("RABBITMQ_PASSWORD"),
|
|
},
|
|
Mail: Mail{
|
|
Host: os.Getenv("MAIL_HOST"),
|
|
Username: os.Getenv("MAIL_USERNAME"),
|
|
Password: os.Getenv("MAIL_PASSWORD"),
|
|
Port: os.Getenv("MAIL_PORT"),
|
|
FromName: os.Getenv("MAIL_FROM_NAME"),
|
|
FromEmail: os.Getenv("MAIL_FROM_EMAIL"),
|
|
},
|
|
Templates: Templates{
|
|
FolderPath: os.Getenv("TEMPLATES_FOLDER_PATH"),
|
|
ConfigPath: os.Getenv("TEMPLATES_CONFIG_PATH"),
|
|
},
|
|
}
|
|
|
|
Cfg = cfg
|
|
}
|