28 lines
411 B
Go
28 lines
411 B
Go
|
package config
|
||
|
|
||
|
import (
|
||
|
"io/ioutil"
|
||
|
|
||
|
yaml "gopkg.in/yaml.v3"
|
||
|
)
|
||
|
|
||
|
const CONFIGFILE = "config.yaml"
|
||
|
|
||
|
type Config struct {
|
||
|
host string `yaml:"host"`
|
||
|
port int `yaml:"port"`
|
||
|
}
|
||
|
|
||
|
func (c *Config) readConfig() (*Config, error) {
|
||
|
yamlFile, err := ioutil.ReadFile(CONFIGFILE)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
err = yaml.Unmarshal([]byte(yamlFile), c)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
return c, nil
|
||
|
}
|