From 969bd7f6189350907cdf0a2620d779e9cce97fe1 Mon Sep 17 00:00:00 2001 From: Martin Geno Date: Thu, 30 Mar 2017 17:02:20 +0200 Subject: [PATCH] clean code --- .gitignore | 1 + cmd/review/config.conf | 1 - cmd/review/main.go | 2 +- lib/database/main.go | 11 +++++------ lib/database/main_test.go | 1 - lib/log/main.go | 6 +++--- lib/log/main_test.go | 8 ++++---- models/config.go | 4 ++-- 8 files changed, 16 insertions(+), 18 deletions(-) create mode 100644 .gitignore delete mode 120000 cmd/review/config.conf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ab4d2d5 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +cmd/review/config.conf diff --git a/cmd/review/config.conf b/cmd/review/config.conf deleted file mode 120000 index 1d43462..0000000 --- a/cmd/review/config.conf +++ /dev/null @@ -1 +0,0 @@ -../../config_example.conf \ No newline at end of file diff --git a/cmd/review/main.go b/cmd/review/main.go index 481a406..35c2c38 100644 --- a/cmd/review/main.go +++ b/cmd/review/main.go @@ -30,7 +30,7 @@ func main() { log.Log.Info("Starting rezension monolith") err := database.Open(config.Database) - if err != nil{ + if err != nil { log.Log.Panic(err) } diff --git a/lib/database/main.go b/lib/database/main.go index c493264..4d971ad 100644 --- a/lib/database/main.go +++ b/lib/database/main.go @@ -2,21 +2,20 @@ package database import ( "github.com/jinzhu/gorm" - _ "github.com/jinzhu/gorm/dialects/sqlite" _ "github.com/jinzhu/gorm/dialects/postgres" + _ "github.com/jinzhu/gorm/dialects/sqlite" ) var ( - Write *gorm.DB - Read *gorm.DB + Write *gorm.DB + Read *gorm.DB config *Config models []interface{} ) - type Config struct { - Type string - Connection string + Type string + Connection string ReadConnection string } diff --git a/lib/database/main_test.go b/lib/database/main_test.go index f0f56b3..636bab8 100644 --- a/lib/database/main_test.go +++ b/lib/database/main_test.go @@ -1,2 +1 @@ package database - diff --git a/lib/log/main.go b/lib/log/main.go index 95869ca..83badc6 100644 --- a/lib/log/main.go +++ b/lib/log/main.go @@ -9,7 +9,7 @@ import ( var Log *logger.Logger -func init(){ +func init() { Log = logger.New() // Enable fallback if core logger is used: log.SetOutput(Log.Writer()) @@ -22,8 +22,8 @@ func HTTP(r *http.Request) *logger.Entry { ip = r.RemoteAddr } return Log.WithFields(logger.Fields{ - "remote": ip, + "remote": ip, "method": r.Method, - "url": r.URL.RequestURI(), + "url": r.URL.RequestURI(), }) } diff --git a/lib/log/main_test.go b/lib/log/main_test.go index 3c54f61..5e5e5c2 100644 --- a/lib/log/main_test.go +++ b/lib/log/main_test.go @@ -3,18 +3,18 @@ package log import ( "net/http" "testing" - + "github.com/stretchr/testify/assert" ) func TestLog(t *testing.T) { assertion := assert.New(t) - + req, _ := http.NewRequest("GET", "https://google.com/lola/duda?q=wasd", nil) log := HTTP(req) _, ok := log.Data["remote"] - - assertion.NotNil(ok, "remote address not set in logger") + + assertion.NotNil(ok, "remote address not set in logger") assertion.Equal("GET", log.Data["method"], "method not set in logger") assertion.Equal("/lola/duda?q=wasd", log.Data["url"], "path not set in logger") } diff --git a/models/config.go b/models/config.go index 3fe5bb7..88b4636 100644 --- a/models/config.go +++ b/models/config.go @@ -5,14 +5,14 @@ import ( "github.com/influxdata/toml" - "github.com/genofire/hs_master-kss-monolith/lib/log" "github.com/genofire/hs_master-kss-monolith/lib/database" + "github.com/genofire/hs_master-kss-monolith/lib/log" ) //Config the config File of this daemon type Config struct { WebserverBind string - Database database.Config + Database database.Config } // ReadConfigFile reads a config model from path of a yml file