RestApiv2/internal/restserver/config.go

37 lines
652 B
Go
Raw Normal View History

package restserver
import (
"io/ioutil"
2023-03-31 20:08:38 +03:00
"git.ukamnya.ru/stulyaganov/RestApiv2/internal/bd"
"gopkg.in/yaml.v3"
)
type Config struct {
2022-12-12 20:34:00 +03:00
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",
2022-12-12 20:34:00 +03:00
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
}