Use the function to parse viper on server side

Signed-off-by: Hu Keping <hukeping@huawei.com>
This commit is contained in:
HuKeping 2015-12-08 14:08:05 +08:00
parent bfe7316de9
commit 639f1e80f0
1 changed files with 3 additions and 15 deletions

View File

@ -8,8 +8,6 @@ import (
"net/http" "net/http"
_ "net/http/pprof" _ "net/http/pprof"
"os" "os"
"path/filepath"
"strings"
"time" "time"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
@ -186,19 +184,9 @@ func main() {
ctx := context.Background() ctx := context.Background()
filename := filepath.Base(configFile) // parse viper config
ext := filepath.Ext(configFile) if err := utils.ParseViper(mainViper, configFile); err != nil {
configPath := filepath.Dir(configFile) logrus.Fatal(err.Error())
mainViper.SetConfigType(strings.TrimPrefix(ext, "."))
mainViper.SetConfigName(strings.TrimSuffix(filename, ext))
mainViper.AddConfigPath(configPath)
err := mainViper.ReadInConfig()
if err != nil {
logrus.Error("Viper Error: ", err.Error())
logrus.Error("Could not read config at ", configFile)
os.Exit(1)
} }
// default is error level // default is error level