From cba35eff9344743525e6f7b83c60e34185d8b381 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Fri, 29 Dec 2017 21:49:50 +0100 Subject: [PATCH] Add fix for config parsing into code This implements a comment from Luzifer/cloudkeys-go#17 in order not to have to change the `config.go` when deploying Signed-off-by: Knut Ahlers --- config.go | 12 +----------- config_default.go | 11 +++++++++++ config_gae.go | 21 +++++++++++++++++++++ 3 files changed, 33 insertions(+), 11 deletions(-) create mode 100644 config_default.go create mode 100644 config_gae.go diff --git a/config.go b/config.go index f2bbf2e..f75795c 100644 --- a/config.go +++ b/config.go @@ -1,10 +1,6 @@ package main -import ( - "net/url" - - "github.com/Luzifer/rconfig" -) +import "net/url" type config struct { // General Config @@ -22,9 +18,3 @@ type config struct { func (c config) ParsedStorage() (*url.URL, error) { return url.Parse(c.Storage) } - -func loadConfig() *config { - cfg := &config{} - rconfig.Parse(cfg) - return cfg -} diff --git a/config_default.go b/config_default.go new file mode 100644 index 0000000..077208c --- /dev/null +++ b/config_default.go @@ -0,0 +1,11 @@ +// +build !appengine + +package main + +import "github.com/Luzifer/rconfig" + +func loadConfig() *config { + cfg := &config{} + rconfig.Parse(cfg) + return cfg +} diff --git a/config_gae.go b/config_gae.go new file mode 100644 index 0000000..59bf2f5 --- /dev/null +++ b/config_gae.go @@ -0,0 +1,21 @@ +// +build appengine + +package main + +import ( + "os" + + "github.com/Luzifer/rconfig" +) + +func loadConfig() *config { + cfg := &config{} + + // Workaround as GAE supplies more parameters than expected. + // This removes all CLI flags for parsing and relies only on parsing + // environment variables. + os.Args = []string{os.Args[0]} + + rconfig.Parse(cfg) + return cfg +}