From 8826be46375219158ec4bb68379f2305ab593b87 Mon Sep 17 00:00:00 2001 From: Jasper Bok Date: Thu, 24 Aug 2023 21:21:52 +0200 Subject: [PATCH] Add flag for passing config file --- main.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 4c1cb55..17cc472 100644 --- a/main.go +++ b/main.go @@ -2,18 +2,35 @@ package main import ( "flag" + "fmt" "net/http" + "os" ) var BusClient *http.Client -var Quays []Quay = []Quay{} +var Quays []Quay func main() { + var confFilename string var port int + flag.StringVar(&confFilename, "c", "", "Path to the configuration file") flag.IntVar(&port, "p", 4444, "The port to start the server on") flag.Parse() + if confFilename == "" { + fmt.Printf("No configuation file provided. Provide the path to a configuration file with the -c flag.\n") + os.Exit(0) + } + + conf, err := ReadConfigFromFile(confFilename) + if err != nil { + fmt.Printf("%v\n", err) + os.Exit(1) + } + + Quays = conf.Quays + BusClient = &http.Client{} serveHttp(port) }