moved from yaml to env config
parent
08858ae641
commit
ea8b3f6d9e
3
go.mod
3
go.mod
|
@ -3,7 +3,7 @@ module clickandjoin.app/emailserver
|
|||
go 1.19
|
||||
|
||||
require (
|
||||
git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper v1.0.39
|
||||
git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper v1.0.45
|
||||
github.com/rabbitmq/amqp091-go v1.5.0
|
||||
github.com/tdewolff/minify/v2 v2.12.4
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
|
@ -13,6 +13,7 @@ require (
|
|||
github.com/gocql/gocql v0.0.0-20211015133455-b225f9b53fa1 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed // indirect
|
||||
github.com/joho/godotenv v1.5.1 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.17 // indirect
|
||||
github.com/rs/zerolog v1.29.0 // indirect
|
||||
|
|
4
go.sum
4
go.sum
|
@ -2,6 +2,8 @@ git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper v1.0.36 h1:tqx39cmvtID3lb
|
|||
git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper v1.0.36/go.mod h1:RnqJsFYGR0cdxbeQjB1dDlr/MeKgnMkc7XoZtFDhMbo=
|
||||
git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper v1.0.39 h1:H9YLpd4hvd0wXzKW050cQIHCg6rTchfKTzxp1dgXYLY=
|
||||
git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper v1.0.39/go.mod h1:Jzc4/4ntrOLMOZYnUjkr1uBCVtRvPbEbQD+8kwBOdf4=
|
||||
git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper v1.0.45 h1:btSDPJJrXbusoLizl7W0IyNe7cYqGfVOuAPVilDwGWE=
|
||||
git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper v1.0.45/go.mod h1:Jzc4/4ntrOLMOZYnUjkr1uBCVtRvPbEbQD+8kwBOdf4=
|
||||
github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k=
|
||||
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
|
||||
github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927/go.mod h1:h/aW8ynjgkuj+NQRlZcDbAbM1ORAbXjXX77sX7T289U=
|
||||
|
@ -18,6 +20,8 @@ github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
|
|||
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8=
|
||||
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
|
|
9
main.go
9
main.go
|
@ -10,7 +10,14 @@ import (
|
|||
func init() {
|
||||
config.LoadConfig()
|
||||
|
||||
gocnjhelper.InitLogger(config.Cfg.Debug, true, true)
|
||||
cfg := config.Cfg
|
||||
|
||||
gocnjhelper.InitLogger(config.Cfg.Debug,
|
||||
true,
|
||||
true,
|
||||
gocnjhelper.GetConnectionString(cfg.RabbitMq.Username, cfg.RabbitMq.Password, cfg.RabbitMq.Host),
|
||||
cfg.ServiceName,
|
||||
cfg.ServiceType)
|
||||
|
||||
mailer.Init()
|
||||
}
|
||||
|
|
|
@ -2,16 +2,19 @@ package config
|
|||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
gocnjhelper "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper"
|
||||
"gopkg.in/yaml.v2"
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
var Cfg Config
|
||||
|
||||
type Config struct {
|
||||
ServiceName uint8
|
||||
ServiceType uint8
|
||||
Debug bool
|
||||
DefaultLanguageCode string `yaml:"defaultLanguageCode"`
|
||||
DefaultLanguageCode string
|
||||
RabbitMq RabbitMq
|
||||
Mail Mail
|
||||
Templates Templates
|
||||
|
@ -37,13 +40,54 @@ type Templates struct {
|
|||
}
|
||||
|
||||
func LoadConfig() {
|
||||
data, err := os.ReadFile("config.yml")
|
||||
// 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 read config file, err: %s", err)
|
||||
gocnjhelper.LogFatalf("Failed to parse boolean, err: %s", err)
|
||||
}
|
||||
|
||||
if err := yaml.Unmarshal(data, &Cfg); err != nil {
|
||||
gocnjhelper.LogFatalf("Failed to unmarshal config file, 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"),
|
||||
From: os.Getenv("MAIL_FROM"),
|
||||
},
|
||||
Templates: Templates{
|
||||
FolderPath: os.Getenv("TEMPLATES_FOLDER_PATH"),
|
||||
ConfigPath: os.Getenv("TEMPLATES_CONFIG_PATH"),
|
||||
},
|
||||
}
|
||||
|
||||
Cfg = cfg
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue