From 003233d60da4a2b69260642e57757bba48021ca1 Mon Sep 17 00:00:00 2001 From: r Date: Sun, 2 Jan 2022 10:52:15 +0000 Subject: Change config file lookup - Look for both local and global config file - Directly generate the global config file with make install --- main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index cac5eee..85ee6cc 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,7 @@ import ( ) var ( - configFile = "/etc/bloat.conf" + configFiles = []string{"bloat.conf", "/etc/bloat.conf"} ) func errExit(err error) { @@ -34,11 +34,11 @@ func main() { for _, opt := range opts { switch opt.Option { case 'f': - configFile = opt.Value + configFiles = []string{opt.Value} } } - config, err := config.ParseFile(configFile) + config, err := config.ParseFiles(configFiles) if err != nil { errExit(err) } -- cgit v1.2.3 From c5f12920b0879498b0a20342650a09b0ad5c9d7c Mon Sep 17 00:00:00 2001 From: r Date: Sun, 2 Jan 2022 11:15:57 +0000 Subject: Use GO's flag parser instead of getopt There's only one flag, so it doesn't matter. --- main.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 85ee6cc..3b5ccba 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "errors" + "flag" "fmt" "log" "net/http" @@ -26,18 +27,12 @@ func errExit(err error) { } func main() { - opts, _, err := util.Getopts(os.Args, "f:") - if err != nil { - errExit(err) - } + configFile := flag.String("f", "", "config file") + flag.Parse() - for _, opt := range opts { - switch opt.Option { - case 'f': - configFiles = []string{opt.Value} - } + if len(*configFile) > 0 { + configFiles = []string{*configFile} } - config, err := config.ParseFiles(configFiles) if err != nil { errExit(err) -- cgit v1.2.3