45 lines
693 B
Go
45 lines
693 B
Go
package pancheri
|
|
|
|
import (
|
|
"github.com/sirupsen/logrus"
|
|
"gopkg.in/yaml.v2"
|
|
"os"
|
|
)
|
|
|
|
type Config struct {
|
|
Server struct {
|
|
Host string `yaml:"host"`
|
|
Port string `yaml:"port"`
|
|
} `yaml:"server"`
|
|
Resolver struct {
|
|
Enable bool `yaml:"enable"`
|
|
Upstream string `yaml:"upstream"`
|
|
}
|
|
Logging struct {
|
|
Format string `yaml:"format"`
|
|
Level logrus.Level `yaml:"level"`
|
|
}
|
|
}
|
|
|
|
func LoadConfig(path string) (*Config, error) {
|
|
f, err := os.Open(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var cfg Config
|
|
decoder := yaml.NewDecoder(f)
|
|
|
|
err = decoder.Decode(&cfg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = f.Close()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &cfg, nil
|
|
}
|