-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
46 lines (37 loc) · 884 Bytes
/
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
package config
import (
"github.com/go-graphql/pkg/logger"
"github.com/ilyakaznacheev/cleanenv"
)
type (
Config struct {
App `yaml:"app"`
HTTP `yaml:"http"`
Database `yaml:"database"`
}
App struct {
Name string `env-required:"true" yaml:"name"`
Version string `env-required:"true" yaml:"version"`
IsUseFakeData bool `env-required:"true" yaml:"is_use_fake_data"`
}
// HTTP -.
HTTP struct {
Port string `env-required:"true" yaml:"port"`
}
Database struct {
PoolMax int `env-required:"true" yaml:"pool_max"`
}
)
// NewConfig returns app config.
func NewConfig() *Config {
cfg := &Config{}
err := cleanenv.ReadConfig("./config/config-development.yml", cfg) // Change this base on your env
if err != nil {
logger.Log.Fatalln(err)
}
err = cleanenv.ReadEnv(cfg)
if err != nil {
logger.Log.Fatalln(err)
}
return cfg
}