From 51c74de1de9e4b6c60b99873b6fb87fe9d9eee08 Mon Sep 17 00:00:00 2001 From: funkythings Date: Fri, 20 Mar 2020 21:21:44 +0000 Subject: [PATCH] expand relative path ~/.config/vikunja to $HOME/.config/vikunja **WINDOWS** (#147) apply correct formatting add quotes to make the yaml gods happy log path of config file used by viper resolve merge conflicts: windows compatible $HOME path Prepare changelog & readme for 0.11 release expand relative path ~/.config/vikunja to $HOME/.config/vikunja (#146) update dependencies expand relative path ~/.config/vikunja Co-authored-by: Julian Co-authored-by: konrad Co-authored-by: Julian Gaal Reviewed-on: https://kolaente.dev/vikunja/api/pulls/147 Reviewed-by: konrad --- config.yml.sample | 2 +- go.mod | 3 --- pkg/config/config.go | 20 ++++++++++++++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/config.yml.sample b/config.yml.sample index fb430ede9..30b149a56 100644 --- a/config.yml.sample +++ b/config.yml.sample @@ -77,7 +77,7 @@ cors: enable: true # A list of origins which may access the api. origins: - - * + - "*" # How long (in seconds) the results of a preflight request can be cached. maxage: 0 diff --git a/go.mod b/go.mod index d9e9daf4d..ef72939f3 100644 --- a/go.mod +++ b/go.mod @@ -40,7 +40,6 @@ require ( github.com/go-testfixtures/testfixtures/v3 v3.1.1 github.com/go-xorm/core v0.6.2 // indirect github.com/go-xorm/xorm v0.7.9 // indirect - github.com/gogo/protobuf v1.2.0 // indirect github.com/golang/protobuf v1.3.2 // indirect github.com/gordonklaus/ineffassign v0.0.0-20180909121442-1003c8bd00dc github.com/imdario/mergo v0.3.7 @@ -56,8 +55,6 @@ require ( github.com/mattn/go-sqlite3 v2.0.3+incompatible github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 github.com/olekukonko/tablewriter v0.0.1 - github.com/onsi/ginkgo v1.7.0 // indirect - github.com/onsi/gomega v1.4.3 // indirect github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 github.com/pelletier/go-toml v1.4.0 // indirect github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829 diff --git a/pkg/config/config.go b/pkg/config/config.go index 9577b2d88..c72687234 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -21,6 +21,7 @@ import ( "fmt" "log" "os" + "path" "path/filepath" "strings" "time" @@ -250,14 +251,25 @@ func InitConfig() { // Load the config file viper.AddConfigPath(ServiceRootpath.GetString()) viper.AddConfigPath("/etc/vikunja/") - viper.AddConfigPath("$HOME/.config/vikunja") - viper.AddConfigPath(".") - viper.SetConfigName("config") - err := viper.ReadInConfig() + + homeDir, err := os.UserHomeDir() if err != nil { log.Println(err.Error()) log.Println("Using defaults.") + return } + + viper.AddConfigPath(path.Join(homeDir, ".config", "vikunja")) + viper.AddConfigPath(".") + viper.SetConfigName("config") + err = viper.ReadInConfig() + if err != nil { + log.Println(err.Error()) + log.Println("Using defaults.") + return + } + + log.Println("Found config file:", viper.ConfigFileUsed()) } func random(length int) (string, error) {