init
This commit is contained in:
42
internal/config/config.go
Normal file
42
internal/config/config.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/ilyakaznacheev/cleanenv"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
AppName string `yaml:"app_name" env:"APP_NAME" env-default:"test"`
|
||||
Server Server `yaml:"server"`
|
||||
Database Database `yaml:"database"`
|
||||
Nats Nats `yaml:"nats"`
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
Port string `yaml:"port" env:"PORT" env-default:"3000"`
|
||||
Host string `yaml:"host" env:"HOST" env-default:"localhost"`
|
||||
}
|
||||
|
||||
type Nats struct {
|
||||
Host string `yaml:"host" env:"NATS_HOST" env-default:"localhost"`
|
||||
Port string `yaml:"port" env:"NATS_PORT" env-default:"4222"`
|
||||
Token string `yaml:"token"`
|
||||
}
|
||||
|
||||
type Database struct {
|
||||
Host string `yaml:"host"`
|
||||
Port string `yaml:"port"`
|
||||
User string `yaml:"user"`
|
||||
Password string `yaml:"password"`
|
||||
Name string `yaml:"name"`
|
||||
}
|
||||
|
||||
func MustLoad(path string) *Config {
|
||||
var config Config
|
||||
|
||||
err := cleanenv.ReadConfig(path, &config)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return &config
|
||||
}
|
||||
Reference in New Issue
Block a user