genofire/hs_monolith
genofire
/
hs_monolith
Archived
1
0
Fork 0

clean code

This commit is contained in:
Martin Geno 2017-03-30 17:02:20 +02:00
parent 6b08576d63
commit 969bd7f618
No known key found for this signature in database
GPG Key ID: F0D39A37E925E941
8 changed files with 16 additions and 18 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
cmd/review/config.conf

View File

@ -1 +0,0 @@
../../config_example.conf

View File

@ -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)
}

View File

@ -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
}

View File

@ -1,2 +1 @@
package database

View File

@ -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(),
})
}

View File

@ -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")
}

View File

@ -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