Drop viper dependency (#550)

* Removed viper dependency.

* removed from glide files
This commit is contained in:
Travis Reeder
2017-11-28 15:46:17 -08:00
committed by GitHub
parent 81e3c4387c
commit a67d5a6290
121 changed files with 90 additions and 21413 deletions

View File

@@ -2,34 +2,25 @@ package server
import (
"context"
"fmt"
"os"
"os/signal"
"strconv"
"strings"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
)
func init() {
viper.AutomaticEnv() // picks up env vars automatically
cwd, err := os.Getwd()
var err error
currDir, err = os.Getwd()
if err != nil {
logrus.WithError(err).Fatalln("")
}
// Replace forward slashes in case this is windows, URL parser errors
cwd = strings.Replace(cwd, "\\", "/", -1)
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.SetDefault(EnvLogLevel, "info")
viper.SetDefault(EnvMQURL, fmt.Sprintf("bolt://%s/data/worker_mq.db", cwd))
viper.SetDefault(EnvDBURL, fmt.Sprintf("sqlite3://%s/data/fn.db", cwd))
viper.SetDefault(EnvLOGDBURL, "") // default to just using DB url
viper.SetDefault(EnvPort, 8080)
viper.SetDefault(EnvZipkinURL, "") // off default
viper.SetDefault(EnvAPIURL, fmt.Sprintf("http://127.0.0.1:%d", viper.GetInt(EnvPort)))
viper.AutomaticEnv() // picks up env vars automatically
logLevel, err := logrus.ParseLevel(viper.GetString(EnvLogLevel))
currDir = strings.Replace(currDir, "\\", "/", -1)
logLevel, err := logrus.ParseLevel(getEnv(EnvLogLevel, DefaultLogLevel))
if err != nil {
logrus.WithError(err).Fatalln("Invalid log level.")
}
@@ -41,6 +32,26 @@ func init() {
}
}
func getEnv(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return fallback
}
func getEnvInt(key string, fallback int) int {
if value, ok := os.LookupEnv(key); ok {
// linter liked this better than if/else
var err error
var i int
if i, err = strconv.Atoi(value); err != nil {
panic(err) // not sure how to handle this
}
return i
}
return fallback
}
func contextWithSignal(ctx context.Context, signals ...os.Signal) (context.Context, context.CancelFunc) {
newCTX, halt := context.WithCancel(ctx)
c := make(chan os.Signal, 1)