pancheri/config.go

52 lines
870 B
Go
Raw Permalink Normal View History

2023-10-01 20:43:10 +00:00
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"`
}
Zone struct {
LoadFiles []string `yaml:"load_files"`
} `yaml:"zone"`
2023-10-03 17:54:57 +00:00
Blackhole struct {
Enable bool `yaml:"enable"`
BlockLists []string `yaml:"block_lists"`
}
2023-10-01 20:43:10 +00:00
}
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
}