Files
GuwandykA 6c7c402390
Some checks failed
CI/CD / Vet, test, build (push) Has been cancelled
CI/CD / Docker image (push) Has been cancelled
CI/CD / Deploy binary to server (push) Has been cancelled
add pay
2026-09-19 03:54:40 +05:00

62 lines
1.7 KiB
Go
Executable File

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"`
PublicBaseURL string `yaml:"public_base_url" env-required:"true"`
Storage StorageConfig `yaml:"storage"`
Minio MinioConfig `yaml:"minio"`
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"`
}
type MinioConfig struct {
Endpoint string `yaml:"endpoint" env-required:"true"`
AccessKey string `yaml:"access_key" env-required:"true"`
SecretKey string `yaml:"secret_key" env-required:"true"`
Bucket string `yaml:"bucket" env-required:"true"`
UseSSL bool `yaml:"use_ssl" env-default:"false"`
}
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
}