From 7a8c0a4d7d24b31cc42b2bb940660174a04770e0 Mon Sep 17 00:00:00 2001 From: Ben Schinn Date: Tue, 25 Aug 2020 15:32:53 -0600 Subject: [PATCH 1/4] add config arg --- main.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index bcf56d2..ec4ffbd 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "encoding/json" "log" "net/http" + "os" "github.com/film42/pgreba/config" "github.com/gorilla/handlers" @@ -78,7 +79,9 @@ func (hc *HealthCheckWebService) apiGetIsReplica(w http.ResponseWriter, r *http. } func main() { - cfg, err := config.ParseConfig("./examples/config.yml") + pathToConfig := os.Args[1] + + cfg, err := config.ParseConfig(pathToConfig) if err != nil { panic(err) } From 054f112f9eb2fe756bd34f32eb20b0eb7b1d3036 Mon Sep 17 00:00:00 2001 From: Ben Schinn Date: Tue, 25 Aug 2020 15:33:59 -0600 Subject: [PATCH 2/4] formatted --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index ec4ffbd..6cdde54 100644 --- a/main.go +++ b/main.go @@ -4,7 +4,7 @@ import ( "encoding/json" "log" "net/http" - "os" + "os" "github.com/film42/pgreba/config" "github.com/gorilla/handlers" @@ -79,7 +79,7 @@ func (hc *HealthCheckWebService) apiGetIsReplica(w http.ResponseWriter, r *http. } func main() { - pathToConfig := os.Args[1] + pathToConfig := os.Args[1] cfg, err := config.ParseConfig(pathToConfig) if err != nil { From 88f07ab3b1719ea573c487b9c93311611f41e11f Mon Sep 17 00:00:00 2001 From: Ben Schinn Date: Tue, 25 Aug 2020 16:32:15 -0600 Subject: [PATCH 3/4] handle exception when no config arg is present --- main.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.go b/main.go index 6cdde54..fae7ae8 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "errors" "log" "net/http" "os" @@ -79,6 +80,9 @@ func (hc *HealthCheckWebService) apiGetIsReplica(w http.ResponseWriter, r *http. } func main() { + if len(os.Args) < 2 { + panic(errors.New("Please provide a path to config yml.")) + } pathToConfig := os.Args[1] cfg, err := config.ParseConfig(pathToConfig) From 0352b41c17782f2b6bc290a0c5857320459a478c Mon Sep 17 00:00:00 2001 From: Ben Schinn Date: Wed, 26 Aug 2020 11:21:13 -0600 Subject: [PATCH 4/4] formatted --- main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index fae7ae8..999065b 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,7 @@ package main import ( "encoding/json" - "errors" + "errors" "log" "net/http" "os" @@ -80,9 +80,9 @@ func (hc *HealthCheckWebService) apiGetIsReplica(w http.ResponseWriter, r *http. } func main() { - if len(os.Args) < 2 { - panic(errors.New("Please provide a path to config yml.")) - } + if len(os.Args) < 2 { + panic(errors.New("Please provide a path to config yml.")) + } pathToConfig := os.Args[1] cfg, err := config.ParseConfig(pathToConfig)