-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
56 lines (45 loc) · 1.02 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
package config
import (
"fmt"
"github.com/ilyakaznacheev/cleanenv"
)
type (
// Config -.
Config struct {
App `yaml:"app"`
HTTP `yaml:"http"`
Log `yaml:"logger"`
PG `yaml:"postgres"`
}
// App -.
App struct {
Name string `env-required:"true" yaml:"name" env:"APP_NAME"`
Version string `env-required:"true" yaml:"version" env:"APP_VERSION"`
}
// HTTP -.
HTTP struct {
Port string `env-required:"true" yaml:"port" env:"HTTP_PORT"`
}
// Log -.
Log struct {
Level string `env-required:"true" yaml:"log_level" env:"LOG_LEVEL"`
}
// PG -.
PG struct {
PoolMax int `env-required:"true" yaml:"pool_max" env:"PG_POOL_MAX"`
URL string `env-required:"true" env:"PG_URL"`
}
)
// NewConfig returns app config.
func NewConfig() (*Config, error) {
cfg := &Config{}
err := cleanenv.ReadConfig("./config/config.yml", cfg)
if err != nil {
return nil, fmt.Errorf("config error: %w", err)
}
err = cleanenv.ReadEnv(cfg)
if err != nil {
return nil, err
}
return cfg, nil
}