Hide 'failed to find config..'

This commit is contained in:
Jannis Mattheis 2018-12-07 19:26:05 +01:00
parent 0f85870d93
commit 193dd67f2c
4 changed files with 39 additions and 9 deletions

19
Gopkg.lock generated
View File

@ -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

View File

@ -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"

View File

@ -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
}

View File

@ -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() {