From 59c8d6cf3637039b9dab6fdd6fe502430837d216 Mon Sep 17 00:00:00 2001 From: cuigh Date: Thu, 26 Oct 2017 17:05:27 +0800 Subject: [PATCH] Switch config to YAML format This is a breaking change if you used file config. --- config/app.prd.yml | 2 ++ config/app.xml | 14 -------------- config/app.yml | 20 ++++++++++++++++++++ config/profile.xml | 8 -------- main.go | 2 +- misc/misc.go | 16 ++++++---------- misc/util.go | 3 +++ 7 files changed, 32 insertions(+), 33 deletions(-) create mode 100644 config/app.prd.yml delete mode 100644 config/app.xml create mode 100644 config/app.yml delete mode 100644 config/profile.xml diff --git a/config/app.prd.yml b/config/app.prd.yml new file mode 100644 index 0000000..69d5743 --- /dev/null +++ b/config/app.prd.yml @@ -0,0 +1,2 @@ +swirl: + docker_endpoint: tcp://docker-proxy:2375 diff --git a/config/app.xml b/config/app.xml deleted file mode 100644 index 7c455b6..0000000 --- a/config/app.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/config/app.yml b/config/app.yml new file mode 100644 index 0000000..c5c858a --- /dev/null +++ b/config/app.yml @@ -0,0 +1,20 @@ +name: swirl + +web: + address: ':8001' + authorize_mode: '*' + +swirl: + db_type: mongo + db_address: localhost:27017/swirl +# docker_endpoint: tcp://docker-proxy:2375 + +#log: +# loggers: +# - level: info +# writers: console +# writers: +# - name: console +# type: console +# format: json +# layout: '[{L}]{T}: {M} - {F:S}{N}' \ No newline at end of file diff --git a/config/profile.xml b/config/profile.xml deleted file mode 100644 index 60563ae..0000000 --- a/config/profile.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/main.go b/main.go index d5f5e6a..09d62f3 100644 --- a/main.go +++ b/main.go @@ -35,7 +35,7 @@ func main() { ws := web.Auto() // set render/validator.. - ws.Renderer = jet.New().SetDebug(config.App().Debug). + ws.Renderer = jet.New().SetDebug(config.GetBool("debug")). AddFunc("time", misc.FormatTime(setting.TimeZone.Offset)). AddFunc("i18n", misc.Message(setting.Language)). AddFuncs(misc.Funcs). diff --git a/misc/misc.go b/misc/misc.go index 1bd0f53..2075933 100644 --- a/misc/misc.go +++ b/misc/misc.go @@ -4,12 +4,11 @@ import ( "os" "github.com/cuigh/auxo/config" - "github.com/cuigh/auxo/data" ) const ( // Version is the version of Swirl - Version = "0.5.6" + Version = "0.6" ) const ( @@ -25,16 +24,13 @@ var ( ) func init() { - options := config.App().GetSection("swirl") - DockerHost = loadOption(options, "docker_endpoint", envDockerEndpoint) - DBType = loadOption(options, "db_type", envDBType) - DBAddress = loadOption(options, "db_address", envDBAddress) + DockerHost = loadOption("swirl.docker_endpoint", envDockerEndpoint) + DBType = loadOption("swirl.db_type", envDBType) + DBAddress = loadOption("swirl.db_address", envDBAddress) } -func loadOption(options data.Options, key, env string) (opt string) { - if options != nil { - opt = options.String(key) - } +func loadOption(key, env string) (opt string) { + opt = config.GetString(key) if opt == "" { opt = os.Getenv(env) } diff --git a/misc/util.go b/misc/util.go index b6ce831..4c43e82 100644 --- a/misc/util.go +++ b/misc/util.go @@ -51,6 +51,9 @@ func Message(lang string) func(key string, args ...interface{}) string { if err != nil { panic(err) } + if t == nil { + panic("can't find language files") + } return func(key string, args ...interface{}) string { if s := t.Format(key, args...); s != "" {