2022-12-07 21:29:01 +03:00
|
|
|
package restserver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
|
2022-12-12 20:34:00 +03:00
|
|
|
"git.ukamnya.ru/stulyaganov/RestApi/internal/bd"
|
2022-12-07 21:29:01 +03:00
|
|
|
"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"`
|
2022-12-07 21:29:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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(),
|
2022-12-07 21:29:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|