-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
48 lines (39 loc) · 1.44 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
package config
import (
"sync"
"github.com/Falokut/image_processing_service/pkg/jaeger"
"github.com/Falokut/image_processing_service/pkg/logging"
"github.com/Falokut/image_processing_service/pkg/metrics"
"github.com/ilyakaznacheev/cleanenv"
)
type Config struct {
LogLevel string `yaml:"log_level" env:"LOG_LEVEL"`
HealthcheckPort string `yaml:"healthcheck_port"`
EnableMetrics bool `yaml:"enable_metrics" env:"ENABLE_METRICS"`
Listen struct {
Host string `yaml:"host" env:"HOST"`
Port string `yaml:"port" env:"PORT"`
Mode string `yaml:"server_mode" env:"SERVER_MODE"` // support GRPC, REST, BOTH
MaxRequestSize int `yaml:"max_request_size" env:"MAX_REQUEST_SIZE"`
MaxResponseSize int `yaml:"max_response_size" env:"MAX_RESPONSE_SIZE"`
} `yaml:"listen"`
PrometheusConfig struct {
Name string `yaml:"service_name" env:"PROMETHEUS_SERVICE_NAME"`
ServerConfig metrics.MetricsServerConfig `yaml:"server_config"`
} `yaml:"prometheus"`
JaegerConfig jaeger.Config `yaml:"jaeger"`
}
const configsPath string = "configs/"
var instance *Config
var once sync.Once
func GetConfig() *Config {
once.Do(func() {
logger := logging.GetLogger()
instance = &Config{}
if err := cleanenv.ReadConfig(configsPath+"config.yml", instance); err != nil {
help, _ := cleanenv.GetDescription(instance, nil)
logger.Fatal(help, " ", err)
}
})
return instance
}