From 193dd67f2c8ad1716705f3b66503c0ddbe354026 Mon Sep 17 00:00:00 2001 From: Jannis Mattheis Date: Fri, 7 Dec 2018 19:26:05 +0100 Subject: [PATCH] Hide 'failed to find config..' --- Gopkg.lock | 19 ++++++++++++------- Gopkg.toml | 4 ++++ config/config.go | 7 +++++-- config/config_test.go | 18 ++++++++++++++++++ 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 03dabeb..2f1d727 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -42,6 +42,12 @@ revision = "a0583e0143b1624142adab07e0e97fe106d99561" version = "v1.3" +[[projects]] + name = "github.com/go-yaml/yaml" + packages = ["."] + revision = "51d6538a90f86fe93ac480b35f37b2be17fef232" + version = "v2.2.2" + [[projects]] name = "github.com/gobuffalo/packr" packages = ["."] @@ -60,6 +66,11 @@ revision = "ea4d1f681babbce9545c9c5f3d5194a789c89f5b" version = "v1.2.0" +[[projects]] + name = "github.com/gotify/configor" + packages = ["."] + revision = "v1.0.1" + [[projects]] branch = "master" name = "github.com/gotify/location" @@ -72,12 +83,6 @@ revision = "cc14fdc9ca0e4c2bafad7458f6ff79fd3947cfbb" version = "v1.0.5" -[[projects]] - branch = "master" - name = "github.com/jinzhu/configor" - packages = ["."] - revision = "6ecfe629230f24c2e92c7894c6ab21b83b757a39" - [[projects]] name = "github.com/jinzhu/gorm" packages = [ @@ -197,6 +202,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "dd487dcd1de5f16454e33fbf7d886d98272b1b9d78052a17ad785efba4f9c17b" + inputs-digest = "32bb5c1ff95d3c1f3c4de97d40df3b8b3dca41f970e2bb486e73a8d325a0e0c3" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 6d6b064..db4b6f0 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -27,6 +27,10 @@ name = "github.com/jmattheis/go-packr-swagger-ui" revision = "v3.10.0" +[[constraint]] + name = "github.com/gotify/configor" + revision = "v1.0.1" + [[constraint]] name = "github.com/golang/crypto" branch = "master" diff --git a/config/config.go b/config/config.go index d885bc2..c8f3e09 100644 --- a/config/config.go +++ b/config/config.go @@ -4,7 +4,7 @@ import ( "path/filepath" "strings" - "github.com/jinzhu/configor" + "github.com/gotify/configor" ) // Configuration is stuff that can be configured externally per env variables or config file (config.yml). @@ -41,7 +41,10 @@ type Configuration struct { // Get returns the configuration extracted from env variables or config file. func Get() *Configuration { conf := new(Configuration) - configor.New(&configor.Config{ENVPrefix: "GOTIFY"}).Load(conf, "config.yml", "/etc/gotify/config.yml") + err := configor.New(&configor.Config{EnvironmentPrefix: "GOTIFY"}).Load(conf, "config.yml", "/etc/gotify/config.yml") + if err != nil { + panic(err) + } addTrailingSlashToPaths(conf) return conf } diff --git a/config/config_test.go b/config/config_test.go index af76d82..666cb1c 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -40,6 +40,24 @@ func TestNotAddSlash(t *testing.T) { os.Unsetenv("GOTIFY_UPLOADEDIMAGESDIR") } +func TestFileWithSyntaxErrors(t *testing.T) { + file, err := os.Create("config.yml") + defer func() { + file.Close() + }() + assert.Nil(t, err) + _, err = file.WriteString(` +sdgsgsdfgsdfg +`) + file.Close() + assert.Nil(t, err) + assert.Panics(t, func() { + Get() + }) + + assert.Nil(t, os.Remove("config.yml")) +} + func TestConfigFile(t *testing.T) { file, err := os.Create("config.yml") defer func() {