settings section
This commit is contained in:
51
internal/config/config.go
Executable file
51
internal/config/config.go
Executable file
@@ -0,0 +1,51 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"online-back/pkg/logging"
|
||||
|
||||
"github.com/ilyakaznacheev/cleanenv"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
IsDebug *bool `yaml:"is_debug" env-required:"true"`
|
||||
Listen struct {
|
||||
Type string `yaml:"type" env-default:"port"`
|
||||
BindIP string `yaml:"bind_ip" env-default:"0.0.0.0"`
|
||||
Port string `yaml:"port" env-default:"8080"`
|
||||
} `yaml:"listen"`
|
||||
PublicFilePath string `yaml:"public_file_path" env-required:"true"`
|
||||
Storage StorageConfig `yaml:"storage"`
|
||||
JwtKey string `yaml:"jwt_key" env-required:"true"`
|
||||
AppVersion string `yaml:"app_version" env-required:"true"`
|
||||
}
|
||||
|
||||
type StorageConfig struct {
|
||||
PgPoolMaxConn int `yaml:"pg_pool_max_conn" env-required:"true"`
|
||||
Host string `yaml:"host"`
|
||||
Port string `yaml:"port"`
|
||||
Database string `yaml:"database"`
|
||||
Username string `yaml:"username"`
|
||||
Password string `yaml:"password"`
|
||||
}
|
||||
|
||||
var (
|
||||
instance *Config
|
||||
once sync.Once
|
||||
)
|
||||
|
||||
func GetConfig() *Config {
|
||||
once.Do(func() {
|
||||
logger := logging.GetLogger()
|
||||
logger.Info("read application configuration")
|
||||
|
||||
instance = &Config{}
|
||||
if err := cleanenv.ReadConfig("./config.yaml", instance); err != nil {
|
||||
help, _ := cleanenv.GetDescription(instance, nil)
|
||||
logger.Info(help)
|
||||
logger.Fatal(err)
|
||||
}
|
||||
})
|
||||
return instance
|
||||
}
|
||||
Reference in New Issue
Block a user