added config path as parameter

This commit is contained in:
Niklas 2020-12-26 21:31:50 +01:00
parent 85db27cdde
commit 5ce381f370

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"flag"
"io/ioutil" "io/ioutil"
"log" "log"
"net" "net"
@ -57,8 +58,8 @@ var anyRecordTypes = []uint16{
dns.TypeCAA, dns.TypeCAA,
} }
func loadConfig() (*config, error) { func loadConfig(configPath string) (*config, error) {
file, err := ioutil.ReadFile("config.yml") file, err := ioutil.ReadFile(configPath)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -324,7 +325,11 @@ func handleRequest(w dns.ResponseWriter, r *dns.Msg, zone zoneView) {
} }
func main() { func main() {
config, err := loadConfig()
configPath := flag.String("c", "/etc/cool-dns/config.yaml", "path to the config file")
flag.Parse()
config, err := loadConfig(*configPath)
if err != nil { if err != nil {
log.Fatalf("Failed to load config: %s", err.Error()) log.Fatalf("Failed to load config: %s", err.Error())
} }