49 lines
1,020 B
Go
49 lines
1,020 B
Go
package config
|
|
|
|
import (
|
|
"github.com/ilyakaznacheev/cleanenv"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
type Config struct {
|
|
Psql Postgres
|
|
JWT JWT
|
|
Srv Server `yaml:"server"`
|
|
Mig Migrations `yaml:"migrations"`
|
|
Mode string `env:"MODE"`
|
|
}
|
|
|
|
type Postgres struct {
|
|
Host string `env:"DB_HOST"`
|
|
Port int `env:"DB_PORT"`
|
|
User string `env:"DB_USER"`
|
|
Password string `env:"DB_PASS"`
|
|
Dbname string `env:"DB_NAME"`
|
|
Sslmode string `env:"DB_SSLMODE"`
|
|
}
|
|
|
|
type JWT struct {
|
|
SecretKey []byte `env:"JWT_SECRET_KEY"`
|
|
}
|
|
|
|
type Server struct {
|
|
Port string `yaml:"port"`
|
|
RequestIDHeader string `yaml:"request_id_header"`
|
|
}
|
|
type Migrations struct {
|
|
Folder string `yaml:"folder"`
|
|
}
|
|
|
|
func GetConfig() Config {
|
|
var cfg Config
|
|
|
|
if err := cleanenv.ReadConfig(".env", &cfg); err != nil {
|
|
log.Fatalf("error occurred while reading config: %s", err)
|
|
}
|
|
|
|
if err := cleanenv.ReadConfig("config.yml", &cfg); err != nil {
|
|
log.Fatalf("error occurred while reading config: %s", err)
|
|
}
|
|
|
|
return cfg
|
|
}
|