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" revision = "a0583e0143b1624142adab07e0e97fe106d99561"
version = "v1.3" version = "v1.3"
[[projects]]
name = "github.com/go-yaml/yaml"
packages = ["."]
revision = "51d6538a90f86fe93ac480b35f37b2be17fef232"
version = "v2.2.2"
[[projects]] [[projects]]
name = "github.com/gobuffalo/packr" name = "github.com/gobuffalo/packr"
packages = ["."] packages = ["."]
@ -60,6 +66,11 @@
revision = "ea4d1f681babbce9545c9c5f3d5194a789c89f5b" revision = "ea4d1f681babbce9545c9c5f3d5194a789c89f5b"
version = "v1.2.0" version = "v1.2.0"
[[projects]]
name = "github.com/gotify/configor"
packages = ["."]
revision = "v1.0.1"
[[projects]] [[projects]]
branch = "master" branch = "master"
name = "github.com/gotify/location" name = "github.com/gotify/location"
@ -72,12 +83,6 @@
revision = "cc14fdc9ca0e4c2bafad7458f6ff79fd3947cfbb" revision = "cc14fdc9ca0e4c2bafad7458f6ff79fd3947cfbb"
version = "v1.0.5" version = "v1.0.5"
[[projects]]
branch = "master"
name = "github.com/jinzhu/configor"
packages = ["."]
revision = "6ecfe629230f24c2e92c7894c6ab21b83b757a39"
[[projects]] [[projects]]
name = "github.com/jinzhu/gorm" name = "github.com/jinzhu/gorm"
packages = [ packages = [
@ -197,6 +202,6 @@
[solve-meta] [solve-meta]
analyzer-name = "dep" analyzer-name = "dep"
analyzer-version = 1 analyzer-version = 1
inputs-digest = "dd487dcd1de5f16454e33fbf7d886d98272b1b9d78052a17ad785efba4f9c17b" inputs-digest = "32bb5c1ff95d3c1f3c4de97d40df3b8b3dca41f970e2bb486e73a8d325a0e0c3"
solver-name = "gps-cdcl" solver-name = "gps-cdcl"
solver-version = 1 solver-version = 1

View File

@ -27,6 +27,10 @@
name = "github.com/jmattheis/go-packr-swagger-ui" name = "github.com/jmattheis/go-packr-swagger-ui"
revision = "v3.10.0" revision = "v3.10.0"
[[constraint]]
name = "github.com/gotify/configor"
revision = "v1.0.1"
[[constraint]] [[constraint]]
name = "github.com/golang/crypto" name = "github.com/golang/crypto"
branch = "master" branch = "master"

View File

@ -4,7 +4,7 @@ import (
"path/filepath" "path/filepath"
"strings" "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). // 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. // Get returns the configuration extracted from env variables or config file.
func Get() *Configuration { func Get() *Configuration {
conf := new(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) addTrailingSlashToPaths(conf)
return conf return conf
} }

View File

@ -40,6 +40,24 @@ func TestNotAddSlash(t *testing.T) {
os.Unsetenv("GOTIFY_UPLOADEDIMAGESDIR") 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) { func TestConfigFile(t *testing.T) {
file, err := os.Create("config.yml") file, err := os.Create("config.yml")
defer func() { defer func() {