1
0
Fork 0
squid-rewriter/config/loader.go

32 lines
589 B
Go

package config
import (
"os"
"gopkg.in/yaml.v2"
)
type Rewrite struct {
Name string `yaml:"name"`
Destination string `yaml:"destination"`
Distro string `yaml:"distro,omitempty"`
Urls []string `yaml:"urls,omitempty"`
Filename string `yaml:"filename,omitempty"`
}
type Config struct {
Rewrites []Rewrite `yaml:"rewrites"`
}
func Load(filename string) (Config, error) {
cfg := Config{}
f, err := os.Open(filename)
if err != nil {
return cfg, err
}
defer f.Close()
decoder := yaml.NewDecoder(f)
err = decoder.Decode(&cfg)
return cfg, err
}