package main import ( "encoding/json" "io/ioutil" "net" "os" ) func LoadConfig(path string) (*Configuration, error) { data, err := ioutil.ReadFile(path) if err != nil { return nil, err } var c Configuration if err := json.Unmarshal(data, &c); err != nil { return nil, err } bindAddress := os.Getenv("GOPHERHOLE_BIND_ADDRESS") if ip := net.ParseIP(bindAddress); ip != nil { c.BindAddress = ip } else { c.BindAddress = net.ParseIP("127.0.0.1") } return &c, nil } type Configuration struct { BindAddress net.IP UseHosts bool `json:"useHosts"` Upstream []string `json:"upstreams"` Blocklists []string `json:"blocklists"` Records map[string]ConfigRecord `json:"records"` } type ConfigRecord struct { Type string Record string } func NewConfig() *Configuration { return &Configuration{ BindAddress: net.IPv4(127, 0, 0, 1), Upstream: []string{"1.1.1.1"}, UseHosts: true, Blocklists: []string{"https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt"}, Records: map[string]ConfigRecord{ "home.internal": ConfigRecord{ Type: "A", Record: "127.0.0.1", }, }, } }