RestApiv2/internal/restserver/config.go

37 lines
650 B
Go

package restserver
import (
"io/ioutil"
"git.ukamnya.ru/stulyaganov/RestApi/internal/bd"
"gopkg.in/yaml.v3"
)
type Config struct {
BindAddr string `yaml:"bind_addr"`
BindPort string `yaml:"bind_port"`
LogLevel string `yaml:"log_level"`
DB *bd.ConfigBD `yaml:"DB"`
}
func NewConfig() *Config {
return &Config{
BindAddr: ":127.0.0.1",
BindPort: ":8080",
LogLevel: "debug",
DB: bd.NewConfig(),
}
}
func (c *Config) SetConfig(path string) error {
yamlPars, err := ioutil.ReadFile(path)
if err != nil {
return err
}
err = yaml.Unmarshal(yamlPars, c)
if err != nil {
return err
}
return nil
}