From 46ce2e65e47e0511a89f58b99e750f97af551dc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Thu, 20 Oct 2022 16:22:16 +0200 Subject: [PATCH] config: Read path from flag --- config/config.go | 8 +++----- server.go | 6 ++++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/config/config.go b/config/config.go index 6767df5..03d9eae 100644 --- a/config/config.go +++ b/config/config.go @@ -7,8 +7,6 @@ import ( "git.sr.ht/~emersion/go-scfg" ) -var configPath string = "/etc/10man-api/config" - var Port string // ConnectionString is used to connect to the database @@ -19,10 +17,10 @@ var Admins []string var Maps []string -func init() { - cfg, err := scfg.Load(configPath) +func ReadConfig(path string) { + cfg, err := scfg.Load(path) if err != nil { - log.Fatalf("could not read config file %q", configPath) + log.Fatalf("could not read config file %q", path) } for _, d := range cfg { diff --git a/server.go b/server.go index d4e5a5a..8a8641f 100644 --- a/server.go +++ b/server.go @@ -15,6 +15,12 @@ import ( ) func main() { + var configPath string + flag.StringVar(&configPath, "config", "/etc/10man-api/config", "config file path") + flag.Parse() + + config.ReadConfig(configPath) + port := os.Getenv("PORT") if port == "" { port = config.Port -- 2.44.0