-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
67 lines (54 loc) · 1.71 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package config
import (
"path/filepath"
"sync"
"github.com/KatachiNo/Perr/pkg/logg"
"github.com/ilyakaznacheev/cleanenv"
)
type Config struct {
Server struct {
Type string `yaml:"type" env-default:"port"`
Port string `yaml:"port" env-default:"8080"`
} `yaml:"server"`
PostgresDb `yaml:"postgresConfigDb"`
}
type PostgresDb struct {
Username string `yaml:"username"`
Host string `yaml:"host"`
Port string `yaml:"port"`
Dbname string `yaml:"dbname"`
SSLMode string `yaml:"sslmode"`
// Password string `yaml:"password" env:"PASSWORD" env-default:"postgres"`
MaxAttemptsForConnection string `yaml:"max-attempts-for-connection" env-default:"10"`
MakeStartTables string `yaml:"make-start-tables" env-default:"false"`
MakeStartAdmin string `yaml:"make-start-admin" env-default:"false"`
}
type EnvConf struct {
Password string `env:"PASSWORD" env:"PASSWORD" env-default:"postgres"`
SigningKeyAdmin string `env:"SIGNINGKEYADMIN"`
SigningKeyUser string `env:"SIGNINGKEYUSER"`
}
var instance *Config
var instance2 *EnvConf
var once sync.Once
func GetConfig() (*Config, *EnvConf) {
once.Do(func() {
l := logg.GetLogger()
l.Info("Getting configuration /configs/config.yml")
instance = &Config{}
path := filepath.Join("configs", "config.yml") //"configs/config.yml"
if err := cleanenv.ReadConfig(path, instance); err != nil {
help, _ := cleanenv.GetDescription(instance, nil)
l.Info(help)
l.Fatal(err)
}
l.Info("Getting configuration .env")
instance2 = &EnvConf{}
if err := cleanenv.ReadConfig(".env", instance2); err != nil {
help, _ := cleanenv.GetDescription(instance2, nil)
l.Info(help)
l.Fatal(err)
}
})
return instance, instance2
}