From c6307bddaaedd9a9fb540a1b6e84ed4d22bafab5 Mon Sep 17 00:00:00 2001 From: Clivern Date: Thu, 14 Mar 2019 23:28:50 +0100 Subject: [PATCH] switch to spf13/viper --- beaver.go | 20 ++-- go.mod | 40 ++++--- go.sum | 107 ++++++++++++++----- internal/app/api/channel_test.go | 8 +- internal/app/api/client_test.go | 8 +- internal/app/api/config_test.go | 8 +- internal/app/cmd/health_test.go | 8 +- internal/app/controller/channel_test.go | 8 +- internal/app/controller/client_test.go | 8 +- internal/app/controller/config_test.go | 8 +- internal/app/controller/health_check_test.go | 8 +- internal/app/controller/home_test.go | 8 +- internal/app/controller/metrics_test.go | 8 +- internal/app/controller/node_test.go | 8 +- internal/app/controller/socket_test.go | 8 +- internal/app/driver/redis.go | 8 +- internal/app/driver/redis_test.go | 8 +- internal/app/middleware/auth.go | 4 +- internal/pkg/logger/logger.go | 50 ++++----- internal/pkg/logger/logger_test.go | 10 +- internal/pkg/utils/helpers.go | 2 +- internal/pkg/utils/validator_test.go | 9 +- 22 files changed, 216 insertions(+), 138 deletions(-) diff --git a/beaver.go b/beaver.go index ba8c2abe..122371ed 100644 --- a/beaver.go +++ b/beaver.go @@ -12,7 +12,7 @@ import ( "github.com/clivern/beaver/internal/app/middleware" "github.com/clivern/beaver/internal/pkg/utils" "github.com/gin-gonic/gin" - "github.com/micro/go-config" + "github.com/spf13/viper" "io" "net/http" "os" @@ -30,7 +30,9 @@ func main() { flag.StringVar(&configFile, "config", "config.dist.yml", "config") flag.Parse() - err := config.LoadFile(configFile) + viper.SetConfigFile(configFile) + + err := viper.ReadInConfig() if err != nil { panic(fmt.Sprintf( @@ -50,10 +52,10 @@ func main() { return } - if config.Get("app", "mode").String("dev") == "prod" { + if viper.GetString("app.mode") == "prod" { gin.SetMode(gin.ReleaseMode) gin.DisableConsoleColor() - f, _ := os.Create(fmt.Sprintf("%s/gin.log", config.Get("log", "path").String("var/logs"))) + f, _ := os.Create(fmt.Sprintf("%s/gin.log", viper.GetString("log.path"))) gin.DefaultWriter = io.MultiWriter(f) } @@ -125,15 +127,15 @@ func main() { go socket.HandleMessages() - if config.Get("app", "tls", "status").Bool(false) { + if viper.GetBool("app.tls.status") { r.RunTLS( - fmt.Sprintf(":%s", strconv.Itoa(config.Get("app", "port").Int(8080))), - config.Get("app", "tls", "pemPath").String(""), - config.Get("app", "tls", "keyPath").String(""), + fmt.Sprintf(":%s", strconv.Itoa(viper.GetInt("app.port"))), + viper.GetString("app.tls.pemPath"), + viper.GetString("app.tls.keyPath"), ) } else { r.Run( - fmt.Sprintf(":%s", strconv.Itoa(config.Get("app", "port").Int(8080))), + fmt.Sprintf(":%s", strconv.Itoa(viper.GetInt("app.port"))), ) } } diff --git a/go.mod b/go.mod index b753ef90..c3765004 100644 --- a/go.mod +++ b/go.mod @@ -1,28 +1,24 @@ module github.com/clivern/beaver require ( - github.com/BurntSushi/toml v0.3.1 - github.com/bitly/go-simplejson v0.5.0 - github.com/dgrijalva/jwt-go v0.0.0-20180921172315-3af4c746e1c2 - github.com/fsnotify/fsnotify v1.4.7 - github.com/ghodss/yaml v1.0.0 - github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7 + github.com/BurntSushi/toml v0.3.1 // indirect + github.com/dgrijalva/jwt-go v3.2.0+incompatible + github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3 // indirect github.com/gin-gonic/gin v1.3.0 - github.com/go-redis/redis v6.14.2+incompatible - github.com/golang/protobuf v1.2.0 - github.com/google/logger v0.0.0-20181112113803-324a7c096a0d - github.com/gorilla/websocket v0.0.0-20181206070239-95ba29eb981b - github.com/hashicorp/hcl v1.0.0 - github.com/imdario/mergo v0.3.6 - github.com/json-iterator/go v1.1.5 - github.com/mattn/go-isatty v0.0.4 - github.com/micro/go-config v0.13.1 - github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd - github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 + github.com/go-redis/redis v6.15.2+incompatible + github.com/golang/protobuf v1.3.1 // indirect + github.com/google/logger v1.0.1 + github.com/gorilla/websocket v1.4.0 + github.com/json-iterator/go v1.1.6 // indirect + github.com/mattn/go-isatty v0.0.7 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.1 // indirect github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 - github.com/satori/go.uuid v0.0.0-20181028125025-b2ce2384e17b - github.com/ugorji/go v1.1.1 - golang.org/x/sys v0.0.0-20181221143128-b4a75ba826a6 - gopkg.in/go-playground/validator.v8 v8.18.2 - gopkg.in/yaml.v2 v2.2.2 + github.com/onsi/ginkgo v1.8.0 // indirect + github.com/onsi/gomega v1.5.0 // indirect + github.com/satori/go.uuid v1.2.0 + github.com/spf13/viper v1.3.2 + golang.org/x/net v0.0.0-20190313220215-9f648a60d977 // indirect + gopkg.in/go-playground/assert.v1 v1.2.1 // indirect + gopkg.in/go-playground/validator.v8 v8.18.2 // indirect ) diff --git a/go.sum b/go.sum index 4c298715..316877ef 100644 --- a/go.sum +++ b/go.sum @@ -1,47 +1,96 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y= -github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA= +github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= +github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= +github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgrijalva/jwt-go v0.0.0-20180921172315-3af4c746e1c2 h1:xhptajUY6xeFJmfsrpVPxXxH0i2JxobVCBDn0iShbkU= -github.com/dgrijalva/jwt-go v0.0.0-20180921172315-3af4c746e1c2/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= -github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7 h1:AzN37oI0cOS+cougNAV9szl6CVoj2RYwzS3DpUQNtlY= -github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s= +github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3 h1:t8FVkw33L+wilf2QiWkw0UV77qRpcH/JHPKGpKa2E8g= +github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s= github.com/gin-gonic/gin v1.3.0 h1:kCmZyPklC0gVdL728E6Aj20uYBJV93nj/TkwBTKhFbs= github.com/gin-gonic/gin v1.3.0/go.mod h1:7cKuhb5qV2ggCFctp2fJQ+ErvciLZrIeoOSOm6mUr7Y= -github.com/go-redis/redis v6.14.2+incompatible h1:UE9pLhzmWf+xHNmZsoccjXosPicuiNaInPgym8nzfg0= -github.com/go-redis/redis v6.14.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= -github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= +github.com/go-redis/redis v6.15.2+incompatible h1:9SpNVG76gr6InJGxoZ6IuuxaCOQwDAhzyXg+Bs+0Sb4= +github.com/go-redis/redis v6.15.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/google/logger v0.0.0-20181112113803-324a7c096a0d h1:1YC9w0bRU6LRB8JEapVhbfB2Iiewl2NsX39p8uxrKbk= -github.com/google/logger v0.0.0-20181112113803-324a7c096a0d/go.mod h1:tQN+I/DyBt051hEHNEzPgIeyy/GD1WJaKbqPScoDKdY= -github.com/gorilla/websocket v0.0.0-20181206070239-95ba29eb981b h1:SCMPL/pS3OPUJDW7FpTje/+eIJEhdBLxaG2iUl3Gkcw= -github.com/gorilla/websocket v0.0.0-20181206070239-95ba29eb981b/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/logger v1.0.1 h1:Jtq7/44yDwUXMaLTYgXFC31zpm6Oku7OI/k4//yVANQ= +github.com/google/logger v1.0.1/go.mod h1:w7O8nrRr0xufejBlQMI83MXqRusvREoJdaAxV+CoAB4= +github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= +github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28= -github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= -github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= -github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs= -github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/micro/go-config v0.13.1 h1:xuiOe3F6QjBOr4dRu6VNfZo7/yfck8coXBFyEL+YxCk= -github.com/micro/go-config v0.13.1/go.mod h1:fVecLls1kW+EJsrlkJYqUmVoJa1epSHhsPMDXppELx0= +github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY= +github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/mattn/go-isatty v0.0.7 h1:UvyT9uN+3r7yLEYSlJsbQGdsaB/a0DlgWP3pql6iwOc= +github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= -github.com/satori/go.uuid v0.0.0-20181028125025-b2ce2384e17b h1:8O/3dJ2dGfuLVN0bo2B0IdkG0L8cjpmFJ4r8eRQBCi8= -github.com/satori/go.uuid v0.0.0-20181028125025-b2ce2384e17b/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= -github.com/ugorji/go v1.1.1 h1:gmervu+jDMvXTbcHQ0pd2wee85nEoE0BsVyEuzkfK8w= -github.com/ugorji/go v1.1.1/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ= -golang.org/x/sys v0.0.0-20181221143128-b4a75ba826a6 h1:IcgEB62HYgAhX0Nd/QrVgZlxlcyxbGQHElLUhW2X4Fo= -golang.org/x/sys v0.0.0-20181221143128-b4a75ba826a6/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w= +github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo= +github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= +github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= +github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/viper v1.3.2 h1:VUFqw5KcqRf7i70GOzW7N+Q7+gxVBkSSqiXB12+JQ4M= +github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= +github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8 h1:3SVOIvH7Ae1KRYyQWRjXWJEA9sS/c/pjvH++55Gr648= +github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= +github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190313220215-9f648a60d977 h1:actzWV6iWn3GLqN8dZjzsB+CLt+gaV2+wsxroxiQI8I= +golang.org/x/net v0.0.0-20190313220215-9f648a60d977/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM= +gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= gopkg.in/go-playground/validator.v8 v8.18.2 h1:lFB4DoMU6B626w8ny76MV7VX6W2VHct2GVOI3xgiMrQ= gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/internal/app/api/channel_test.go b/internal/app/api/channel_test.go index 239e4ba1..979574e1 100644 --- a/internal/app/api/channel_test.go +++ b/internal/app/api/channel_test.go @@ -6,8 +6,8 @@ package api import ( "fmt" - "github.com/micro/go-config" "github.com/nbio/st" + "github.com/spf13/viper" "os" "strconv" "testing" @@ -19,7 +19,9 @@ func init() { basePath := fmt.Sprintf("%s/src/github.com/clivern/beaver", os.Getenv("GOPATH")) configFile := fmt.Sprintf("%s/%s", basePath, "config.test.yml") - err := config.LoadFile(configFile) + viper.SetConfigFile(configFile) + + err := viper.ReadInConfig() if err != nil { panic(fmt.Sprintf( @@ -30,7 +32,7 @@ func init() { } os.Setenv("BeaverBasePath", fmt.Sprintf("%s/", basePath)) - os.Setenv("PORT", strconv.Itoa(config.Get("app", "port").Int(8080))) + os.Setenv("PORT", strconv.Itoa(viper.GetInt("app.port"))) } // TestChannelAPI test cases diff --git a/internal/app/api/client_test.go b/internal/app/api/client_test.go index 647ffcb2..e76af69b 100644 --- a/internal/app/api/client_test.go +++ b/internal/app/api/client_test.go @@ -6,8 +6,8 @@ package api import ( "fmt" - "github.com/micro/go-config" "github.com/nbio/st" + "github.com/spf13/viper" "os" "strconv" "testing" @@ -19,7 +19,9 @@ func init() { basePath := fmt.Sprintf("%s/src/github.com/clivern/beaver", os.Getenv("GOPATH")) configFile := fmt.Sprintf("%s/%s", basePath, "config.test.yml") - err := config.LoadFile(configFile) + viper.SetConfigFile(configFile) + + err := viper.ReadInConfig() if err != nil { panic(fmt.Sprintf( @@ -30,7 +32,7 @@ func init() { } os.Setenv("BeaverBasePath", fmt.Sprintf("%s/", basePath)) - os.Setenv("PORT", strconv.Itoa(config.Get("app", "port").Int(8080))) + os.Setenv("PORT", strconv.Itoa(viper.GetInt("app.port"))) } // TestClientAPI test cases diff --git a/internal/app/api/config_test.go b/internal/app/api/config_test.go index b0372b2e..37883aed 100644 --- a/internal/app/api/config_test.go +++ b/internal/app/api/config_test.go @@ -6,8 +6,8 @@ package api import ( "fmt" - "github.com/micro/go-config" "github.com/nbio/st" + "github.com/spf13/viper" "os" "strconv" "testing" @@ -18,7 +18,9 @@ func init() { basePath := fmt.Sprintf("%s/src/github.com/clivern/beaver", os.Getenv("GOPATH")) configFile := fmt.Sprintf("%s/%s", basePath, "config.test.yml") - err := config.LoadFile(configFile) + viper.SetConfigFile(configFile) + + err := viper.ReadInConfig() if err != nil { panic(fmt.Sprintf( @@ -29,7 +31,7 @@ func init() { } os.Setenv("BeaverBasePath", fmt.Sprintf("%s/", basePath)) - os.Setenv("PORT", strconv.Itoa(config.Get("app", "port").Int(8080))) + os.Setenv("PORT", strconv.Itoa(viper.GetInt("app.port"))) } // TestConfigAPI test cases diff --git a/internal/app/cmd/health_test.go b/internal/app/cmd/health_test.go index 7cb7187c..b32b6ca5 100644 --- a/internal/app/cmd/health_test.go +++ b/internal/app/cmd/health_test.go @@ -6,8 +6,8 @@ package cmd import ( "fmt" - "github.com/micro/go-config" "github.com/nbio/st" + "github.com/spf13/viper" "os" "strconv" "testing" @@ -18,7 +18,9 @@ func init() { basePath := fmt.Sprintf("%s/src/github.com/clivern/beaver", os.Getenv("GOPATH")) configFile := fmt.Sprintf("%s/%s", basePath, "config.test.yml") - err := config.LoadFile(configFile) + viper.SetConfigFile(configFile) + + err := viper.ReadInConfig() if err != nil { panic(fmt.Sprintf( @@ -29,7 +31,7 @@ func init() { } os.Setenv("BeaverBasePath", fmt.Sprintf("%s/", basePath)) - os.Setenv("PORT", strconv.Itoa(config.Get("app", "port").Int(8080))) + os.Setenv("PORT", strconv.Itoa(viper.GetInt("app.port"))) } // TestHealthStatus test cases diff --git a/internal/app/controller/channel_test.go b/internal/app/controller/channel_test.go index 70bf6090..2836c8dc 100644 --- a/internal/app/controller/channel_test.go +++ b/internal/app/controller/channel_test.go @@ -8,8 +8,8 @@ import ( "fmt" "github.com/clivern/beaver/internal/app/api" "github.com/gin-gonic/gin" - "github.com/micro/go-config" "github.com/nbio/st" + "github.com/spf13/viper" "net/http" "net/http/httptest" "os" @@ -24,7 +24,9 @@ func init() { basePath := fmt.Sprintf("%s/src/github.com/clivern/beaver", os.Getenv("GOPATH")) configFile := fmt.Sprintf("%s/%s", basePath, "config.test.yml") - err := config.LoadFile(configFile) + viper.SetConfigFile(configFile) + + err := viper.ReadInConfig() if err != nil { panic(fmt.Sprintf( @@ -35,7 +37,7 @@ func init() { } os.Setenv("BeaverBasePath", fmt.Sprintf("%s/", basePath)) - os.Setenv("PORT", strconv.Itoa(config.Get("app", "port").Int(8080))) + os.Setenv("PORT", strconv.Itoa(viper.GetInt("app.port"))) } // TestGetChannel1 test case diff --git a/internal/app/controller/client_test.go b/internal/app/controller/client_test.go index d7f8db99..ffcc7735 100644 --- a/internal/app/controller/client_test.go +++ b/internal/app/controller/client_test.go @@ -8,8 +8,8 @@ import ( "fmt" "github.com/clivern/beaver/internal/app/api" "github.com/gin-gonic/gin" - "github.com/micro/go-config" "github.com/nbio/st" + "github.com/spf13/viper" "net/http" "net/http/httptest" "os" @@ -24,7 +24,9 @@ func init() { basePath := fmt.Sprintf("%s/src/github.com/clivern/beaver", os.Getenv("GOPATH")) configFile := fmt.Sprintf("%s/%s", basePath, "config.test.yml") - err := config.LoadFile(configFile) + viper.SetConfigFile(configFile) + + err := viper.ReadInConfig() if err != nil { panic(fmt.Sprintf( @@ -35,7 +37,7 @@ func init() { } os.Setenv("BeaverBasePath", fmt.Sprintf("%s/", basePath)) - os.Setenv("PORT", strconv.Itoa(config.Get("app", "port").Int(8080))) + os.Setenv("PORT", strconv.Itoa(viper.GetInt("app.port"))) } // TestGetClient1 test case diff --git a/internal/app/controller/config_test.go b/internal/app/controller/config_test.go index 13cb2814..6a3446ab 100644 --- a/internal/app/controller/config_test.go +++ b/internal/app/controller/config_test.go @@ -8,8 +8,8 @@ import ( "fmt" "github.com/clivern/beaver/internal/app/api" "github.com/gin-gonic/gin" - "github.com/micro/go-config" "github.com/nbio/st" + "github.com/spf13/viper" "net/http" "net/http/httptest" "os" @@ -23,7 +23,9 @@ func init() { basePath := fmt.Sprintf("%s/src/github.com/clivern/beaver", os.Getenv("GOPATH")) configFile := fmt.Sprintf("%s/%s", basePath, "config.test.yml") - err := config.LoadFile(configFile) + viper.SetConfigFile(configFile) + + err := viper.ReadInConfig() if err != nil { panic(fmt.Sprintf( @@ -34,7 +36,7 @@ func init() { } os.Setenv("BeaverBasePath", fmt.Sprintf("%s/", basePath)) - os.Setenv("PORT", strconv.Itoa(config.Get("app", "port").Int(8080))) + os.Setenv("PORT", strconv.Itoa(viper.GetInt("app.port"))) } // TestGetConfig1 test case diff --git a/internal/app/controller/health_check_test.go b/internal/app/controller/health_check_test.go index 12c7921f..87acb7e6 100644 --- a/internal/app/controller/health_check_test.go +++ b/internal/app/controller/health_check_test.go @@ -7,8 +7,8 @@ package controller import ( "fmt" "github.com/gin-gonic/gin" - "github.com/micro/go-config" "github.com/nbio/st" + "github.com/spf13/viper" "net/http" "net/http/httptest" "os" @@ -21,7 +21,9 @@ func init() { basePath := fmt.Sprintf("%s/src/github.com/clivern/beaver", os.Getenv("GOPATH")) configFile := fmt.Sprintf("%s/%s", basePath, "config.test.yml") - err := config.LoadFile(configFile) + viper.SetConfigFile(configFile) + + err := viper.ReadInConfig() if err != nil { panic(fmt.Sprintf( @@ -32,7 +34,7 @@ func init() { } os.Setenv("BeaverBasePath", fmt.Sprintf("%s/", basePath)) - os.Setenv("PORT", strconv.Itoa(config.Get("app", "port").Int(8080))) + os.Setenv("PORT", strconv.Itoa(viper.GetInt("app.port"))) } // TestHealthCheckController test case diff --git a/internal/app/controller/home_test.go b/internal/app/controller/home_test.go index b4432e0f..5c8443dd 100644 --- a/internal/app/controller/home_test.go +++ b/internal/app/controller/home_test.go @@ -7,8 +7,8 @@ package controller import ( "fmt" "github.com/gin-gonic/gin" - "github.com/micro/go-config" "github.com/nbio/st" + "github.com/spf13/viper" "net/http" "net/http/httptest" "os" @@ -21,7 +21,9 @@ func init() { basePath := fmt.Sprintf("%s/src/github.com/clivern/beaver", os.Getenv("GOPATH")) configFile := fmt.Sprintf("%s/%s", basePath, "config.test.yml") - err := config.LoadFile(configFile) + viper.SetConfigFile(configFile) + + err := viper.ReadInConfig() if err != nil { panic(fmt.Sprintf( @@ -32,7 +34,7 @@ func init() { } os.Setenv("BeaverBasePath", fmt.Sprintf("%s/", basePath)) - os.Setenv("PORT", strconv.Itoa(config.Get("app", "port").Int(8080))) + os.Setenv("PORT", strconv.Itoa(viper.GetInt("app.port"))) } // TestHomeController test case diff --git a/internal/app/controller/metrics_test.go b/internal/app/controller/metrics_test.go index 477cf8cc..d76b9940 100644 --- a/internal/app/controller/metrics_test.go +++ b/internal/app/controller/metrics_test.go @@ -7,8 +7,8 @@ package controller import ( "fmt" "github.com/gin-gonic/gin" - "github.com/micro/go-config" "github.com/nbio/st" + "github.com/spf13/viper" "net/http" "net/http/httptest" "os" @@ -21,7 +21,9 @@ func init() { basePath := fmt.Sprintf("%s/src/github.com/clivern/beaver", os.Getenv("GOPATH")) configFile := fmt.Sprintf("%s/%s", basePath, "config.test.yml") - err := config.LoadFile(configFile) + viper.SetConfigFile(configFile) + + err := viper.ReadInConfig() if err != nil { panic(fmt.Sprintf( @@ -32,7 +34,7 @@ func init() { } os.Setenv("BeaverBasePath", fmt.Sprintf("%s/", basePath)) - os.Setenv("PORT", strconv.Itoa(config.Get("app", "port").Int(8080))) + os.Setenv("PORT", strconv.Itoa(viper.GetInt("app.port"))) } // TestMetricsController test case diff --git a/internal/app/controller/node_test.go b/internal/app/controller/node_test.go index c7c33f46..2c5281c8 100644 --- a/internal/app/controller/node_test.go +++ b/internal/app/controller/node_test.go @@ -7,8 +7,8 @@ package controller import ( "fmt" "github.com/gin-gonic/gin" - "github.com/micro/go-config" "github.com/nbio/st" + "github.com/spf13/viper" "net/http" "net/http/httptest" "os" @@ -21,7 +21,9 @@ func init() { basePath := fmt.Sprintf("%s/src/github.com/clivern/beaver", os.Getenv("GOPATH")) configFile := fmt.Sprintf("%s/%s", basePath, "config.test.yml") - err := config.LoadFile(configFile) + viper.SetConfigFile(configFile) + + err := viper.ReadInConfig() if err != nil { panic(fmt.Sprintf( @@ -32,7 +34,7 @@ func init() { } os.Setenv("BeaverBasePath", fmt.Sprintf("%s/", basePath)) - os.Setenv("PORT", strconv.Itoa(config.Get("app", "port").Int(8080))) + os.Setenv("PORT", strconv.Itoa(viper.GetInt("app.port"))) } // TestNodeController test case diff --git a/internal/app/controller/socket_test.go b/internal/app/controller/socket_test.go index 25da938b..326bd21a 100644 --- a/internal/app/controller/socket_test.go +++ b/internal/app/controller/socket_test.go @@ -7,8 +7,8 @@ package controller import ( "fmt" _ "github.com/gin-gonic/gin" - "github.com/micro/go-config" _ "github.com/nbio/st" + "github.com/spf13/viper" _ "net/http" _ "net/http/httptest" "os" @@ -21,7 +21,9 @@ func init() { basePath := fmt.Sprintf("%s/src/github.com/clivern/beaver", os.Getenv("GOPATH")) configFile := fmt.Sprintf("%s/%s", basePath, "config.test.yml") - err := config.LoadFile(configFile) + viper.SetConfigFile(configFile) + + err := viper.ReadInConfig() if err != nil { panic(fmt.Sprintf( @@ -32,5 +34,5 @@ func init() { } os.Setenv("BeaverBasePath", fmt.Sprintf("%s/", basePath)) - os.Setenv("PORT", strconv.Itoa(config.Get("app", "port").Int(8080))) + os.Setenv("PORT", strconv.Itoa(viper.GetInt("app.port"))) } diff --git a/internal/app/driver/redis.go b/internal/app/driver/redis.go index c7527a22..83344853 100644 --- a/internal/app/driver/redis.go +++ b/internal/app/driver/redis.go @@ -6,7 +6,7 @@ package driver import ( "github.com/go-redis/redis" - "github.com/micro/go-config" + "github.com/spf13/viper" "time" ) @@ -21,9 +21,9 @@ type Redis struct { // NewRedisDriver create a new instance func NewRedisDriver() *Redis { return &Redis{ - Addr: config.Get("redis", "addr").String("localhost:6379"), - Password: config.Get("redis", "password").String(""), - DB: config.Get("redis", "db").Int(0), + Addr: viper.GetString("redis.addr"), + Password: viper.GetString("redis.password"), + DB: viper.GetInt("redis.db"), } } diff --git a/internal/app/driver/redis_test.go b/internal/app/driver/redis_test.go index 00e6f6f8..ff38635c 100644 --- a/internal/app/driver/redis_test.go +++ b/internal/app/driver/redis_test.go @@ -6,8 +6,8 @@ package driver import ( "fmt" - "github.com/micro/go-config" "github.com/nbio/st" + "github.com/spf13/viper" "os" "strconv" "testing" @@ -18,7 +18,9 @@ func init() { basePath := fmt.Sprintf("%s/src/github.com/clivern/beaver", os.Getenv("GOPATH")) configFile := fmt.Sprintf("%s/%s", basePath, "config.test.yml") - err := config.LoadFile(configFile) + viper.SetConfigFile(configFile) + + err := viper.ReadInConfig() if err != nil { panic(fmt.Sprintf( @@ -29,7 +31,7 @@ func init() { } os.Setenv("BeaverBasePath", fmt.Sprintf("%s/", basePath)) - os.Setenv("PORT", strconv.Itoa(config.Get("app", "port").Int(8080))) + os.Setenv("PORT", strconv.Itoa(viper.GetInt("app.port"))) } // TestRedisDriver test cases diff --git a/internal/app/middleware/auth.go b/internal/app/middleware/auth.go index a1758717..91fd4adf 100644 --- a/internal/app/middleware/auth.go +++ b/internal/app/middleware/auth.go @@ -7,7 +7,7 @@ package middleware import ( "github.com/clivern/beaver/internal/pkg/logger" "github.com/gin-gonic/gin" - "github.com/micro/go-config" + "github.com/spf13/viper" "net/http" "strings" ) @@ -20,7 +20,7 @@ func Auth() gin.HandlerFunc { if strings.Contains(path, "/api/") { authToken := c.GetHeader("X-AUTH-TOKEN") - if authToken != config.Get("api", "token").String("") { + if authToken != viper.GetString("api.token") { logger.Infof( `Unauthorized access to %s:%s with token %s {"correlationId":"%s"}`, method, diff --git a/internal/pkg/logger/logger.go b/internal/pkg/logger/logger.go index 7538cf32..77ec12b9 100644 --- a/internal/pkg/logger/logger.go +++ b/internal/pkg/logger/logger.go @@ -7,7 +7,7 @@ package logger import ( "fmt" "github.com/google/logger" - "github.com/micro/go-config" + "github.com/spf13/viper" "os" "time" ) @@ -15,7 +15,7 @@ import ( // Info log func Info(v ...interface{}) { - logLevel := config.Get("log", "level").String("info") + logLevel := viper.GetString("log.level") ok := logLevel == "info" if ok { @@ -23,7 +23,7 @@ func Info(v ...interface{}) { file := fmt.Sprintf( "%s%s/%s.log", os.Getenv("BeaverBasePath"), - config.Get("log", "path").String("var/logs"), + viper.GetString("log.path"), currentTime.Format("2006-01-02"), ) lf, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0660) @@ -44,7 +44,7 @@ func Info(v ...interface{}) { // Infoln log func Infoln(v ...interface{}) { - logLevel := config.Get("log", "level").String("info") + logLevel := viper.GetString("log.level") ok := logLevel == "info" if ok { @@ -52,7 +52,7 @@ func Infoln(v ...interface{}) { file := fmt.Sprintf( "%s%s/%s.log", os.Getenv("BeaverBasePath"), - config.Get("log", "path").String("var/logs"), + viper.GetString("log.path"), currentTime.Format("2006-01-02"), ) lf, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0660) @@ -73,7 +73,7 @@ func Infoln(v ...interface{}) { // Infof log func Infof(format string, v ...interface{}) { - logLevel := config.Get("log", "level").String("info") + logLevel := viper.GetString("log.level") ok := logLevel == "info" if ok { @@ -81,7 +81,7 @@ func Infof(format string, v ...interface{}) { file := fmt.Sprintf( "%s%s/%s.log", os.Getenv("BeaverBasePath"), - config.Get("log", "path").String("var/logs"), + viper.GetString("log.path"), currentTime.Format("2006-01-02"), ) lf, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0660) @@ -102,7 +102,7 @@ func Infof(format string, v ...interface{}) { // Warning log func Warning(v ...interface{}) { - logLevel := config.Get("log", "level").String("info") + logLevel := viper.GetString("log.level") ok := logLevel == "info" || logLevel == "warning" if ok { @@ -110,7 +110,7 @@ func Warning(v ...interface{}) { file := fmt.Sprintf( "%s%s/%s.log", os.Getenv("BeaverBasePath"), - config.Get("log", "path").String("var/logs"), + viper.GetString("log.path"), currentTime.Format("2006-01-02"), ) lf, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0660) @@ -131,7 +131,7 @@ func Warning(v ...interface{}) { // Warningln log func Warningln(v ...interface{}) { - logLevel := config.Get("log", "level").String("info") + logLevel := viper.GetString("log.level") ok := logLevel == "info" || logLevel == "warning" if ok { @@ -139,7 +139,7 @@ func Warningln(v ...interface{}) { file := fmt.Sprintf( "%s%s/%s.log", os.Getenv("BeaverBasePath"), - config.Get("log", "path").String("var/logs"), + viper.GetString("log.path"), currentTime.Format("2006-01-02"), ) lf, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0660) @@ -160,7 +160,7 @@ func Warningln(v ...interface{}) { // Warningf log func Warningf(format string, v ...interface{}) { - logLevel := config.Get("log", "level").String("info") + logLevel := viper.GetString("log.level") ok := logLevel == "info" || logLevel == "warning" if ok { @@ -168,7 +168,7 @@ func Warningf(format string, v ...interface{}) { file := fmt.Sprintf( "%s%s/%s.log", os.Getenv("BeaverBasePath"), - config.Get("log", "path").String("var/logs"), + viper.GetString("log.path"), currentTime.Format("2006-01-02"), ) lf, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0660) @@ -189,7 +189,7 @@ func Warningf(format string, v ...interface{}) { // Error log func Error(v ...interface{}) { - logLevel := config.Get("log", "level").String("info") + logLevel := viper.GetString("log.level") ok := logLevel == "info" || logLevel == "warning" || logLevel == "error" if ok { @@ -197,7 +197,7 @@ func Error(v ...interface{}) { file := fmt.Sprintf( "%s%s/%s.log", os.Getenv("BeaverBasePath"), - config.Get("log", "path").String("var/logs"), + viper.GetString("log.path"), currentTime.Format("2006-01-02"), ) lf, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0660) @@ -218,7 +218,7 @@ func Error(v ...interface{}) { // Errorln log func Errorln(v ...interface{}) { - logLevel := config.Get("log", "level").String("info") + logLevel := viper.GetString("log.level") ok := logLevel == "info" || logLevel == "warning" || logLevel == "error" if ok { @@ -226,7 +226,7 @@ func Errorln(v ...interface{}) { file := fmt.Sprintf( "%s%s/%s.log", os.Getenv("BeaverBasePath"), - config.Get("log", "path").String("var/logs"), + viper.GetString("log.path"), currentTime.Format("2006-01-02"), ) lf, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0660) @@ -247,7 +247,7 @@ func Errorln(v ...interface{}) { // Errorf log func Errorf(format string, v ...interface{}) { - logLevel := config.Get("log", "level").String("info") + logLevel := viper.GetString("log.level") ok := logLevel == "info" || logLevel == "warning" || logLevel == "error" if ok { @@ -255,7 +255,7 @@ func Errorf(format string, v ...interface{}) { file := fmt.Sprintf( "%s%s/%s.log", os.Getenv("BeaverBasePath"), - config.Get("log", "path").String("var/logs"), + viper.GetString("log.path"), currentTime.Format("2006-01-02"), ) lf, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0660) @@ -276,7 +276,7 @@ func Errorf(format string, v ...interface{}) { // Fatal log func Fatal(v ...interface{}) { - logLevel := config.Get("log", "level").String("info") + logLevel := viper.GetString("log.level") ok := logLevel == "info" || logLevel == "warning" || logLevel == "error" || logLevel == "fatal" if ok { @@ -284,7 +284,7 @@ func Fatal(v ...interface{}) { file := fmt.Sprintf( "%s%s/%s.log", os.Getenv("BeaverBasePath"), - config.Get("log", "path").String("var/logs"), + viper.GetString("log.path"), currentTime.Format("2006-01-02"), ) lf, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0660) @@ -305,7 +305,7 @@ func Fatal(v ...interface{}) { // Fatalln log func Fatalln(v ...interface{}) { - logLevel := config.Get("log", "level").String("info") + logLevel := viper.GetString("log.level") ok := logLevel == "info" || logLevel == "warning" || logLevel == "error" || logLevel == "fatal" if ok { @@ -313,7 +313,7 @@ func Fatalln(v ...interface{}) { file := fmt.Sprintf( "%s%s/%s.log", os.Getenv("BeaverBasePath"), - config.Get("log", "path").String("var/logs"), + viper.GetString("log.path"), currentTime.Format("2006-01-02"), ) lf, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0660) @@ -334,7 +334,7 @@ func Fatalln(v ...interface{}) { // Fatalf log func Fatalf(format string, v ...interface{}) { - logLevel := config.Get("log", "level").String("info") + logLevel := viper.GetString("log.level") ok := logLevel == "info" || logLevel == "warning" || logLevel == "error" || logLevel == "fatal" if ok { @@ -342,7 +342,7 @@ func Fatalf(format string, v ...interface{}) { file := fmt.Sprintf( "%s%s/%s.log", os.Getenv("BeaverBasePath"), - config.Get("log", "path").String("var/logs"), + viper.GetString("log.path"), currentTime.Format("2006-01-02"), ) lf, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0660) diff --git a/internal/pkg/logger/logger_test.go b/internal/pkg/logger/logger_test.go index 6ca891b5..66455fbd 100644 --- a/internal/pkg/logger/logger_test.go +++ b/internal/pkg/logger/logger_test.go @@ -6,8 +6,8 @@ package logger import ( "fmt" - "github.com/micro/go-config" "github.com/nbio/st" + "github.com/spf13/viper" "io/ioutil" "os" "strconv" @@ -21,7 +21,9 @@ func init() { basePath := fmt.Sprintf("%s/src/github.com/clivern/beaver", os.Getenv("GOPATH")) configFile := fmt.Sprintf("%s/%s", basePath, "config.test.yml") - err := config.LoadFile(configFile) + viper.SetConfigFile(configFile) + + err := viper.ReadInConfig() if err != nil { panic(fmt.Sprintf( @@ -32,7 +34,7 @@ func init() { } os.Setenv("BeaverBasePath", fmt.Sprintf("%s/", basePath)) - os.Setenv("PORT", strconv.Itoa(config.Get("app", "port").Int(8080))) + os.Setenv("PORT", strconv.Itoa(viper.GetInt("app.port"))) } // TestLogging test cases @@ -43,7 +45,7 @@ func TestLogging(t *testing.T) { logFile := fmt.Sprintf( "%s%s/%s.log", os.Getenv("BeaverBasePath"), - config.Get("log", "path").String("var/logs"), + viper.GetString("log.path"), currentTime.Format("2006-01-02"), ) diff --git a/internal/pkg/utils/helpers.go b/internal/pkg/utils/helpers.go index 2e1784ef..7287b867 100644 --- a/internal/pkg/utils/helpers.go +++ b/internal/pkg/utils/helpers.go @@ -15,7 +15,7 @@ import ( // GenerateUUID4 create a UUID func GenerateUUID4() string { - u := uuid.Must(uuid.NewV4()) + u := uuid.Must(uuid.NewV4(), nil) return u.String() } diff --git a/internal/pkg/utils/validator_test.go b/internal/pkg/utils/validator_test.go index 9232a9c6..ffd42d59 100644 --- a/internal/pkg/utils/validator_test.go +++ b/internal/pkg/utils/validator_test.go @@ -6,8 +6,8 @@ package utils import ( "fmt" - "github.com/micro/go-config" "github.com/nbio/st" + "github.com/spf13/viper" "os" "strconv" "testing" @@ -18,7 +18,9 @@ func init() { basePath := fmt.Sprintf("%s/src/github.com/clivern/beaver", os.Getenv("GOPATH")) configFile := fmt.Sprintf("%s/%s", basePath, "config.test.yml") - err := config.LoadFile(configFile) + viper.SetConfigFile(configFile) + + err := viper.ReadInConfig() if err != nil { panic(fmt.Sprintf( @@ -28,7 +30,8 @@ func init() { )) } - os.Setenv("PORT", strconv.Itoa(config.Get("app", "port").Int(8080))) + os.Setenv("BeaverBasePath", fmt.Sprintf("%s/", basePath)) + os.Setenv("PORT", strconv.Itoa(viper.GetInt("app.port"))) } // TestValidation test cases