diff --git a/cmd/review/config.conf b/cmd/review/config.conf new file mode 120000 index 0000000..1d43462 --- /dev/null +++ b/cmd/review/config.conf @@ -0,0 +1 @@ +../../config_example.conf \ No newline at end of file diff --git a/cmd/rezension/main.go b/cmd/review/main.go similarity index 65% rename from cmd/rezension/main.go rename to cmd/review/main.go index 979a831..e8b671a 100644 --- a/cmd/rezension/main.go +++ b/cmd/review/main.go @@ -2,7 +2,6 @@ package main import ( "flag" - "log" "net/http" "os" "os/signal" @@ -10,35 +9,28 @@ import ( goji "goji.io" - http_api "github.com/genofire/hs_master-kss-monolith/http" - "github.com/genofire/hs_master-kss-monolith/lib" + web "github.com/genofire/hs_master-kss-monolith/http" + "github.com/genofire/hs_master-kss-monolith/lib/log" "github.com/genofire/hs_master-kss-monolith/models" ) var ( configFile string config *models.Config - timestamps bool ) func main() { - flag.BoolVar(×tamps, "timestamps", true, "print timestamps in output") flag.StringVar(&configFile, "config", "config.conf", "path of configuration file (default:config.conf)") flag.Parse() // load config config = models.ReadConfigFile(configFile) - if !timestamps { - log.SetFlags(0) - lib.LogTimestamp(false) - } - - log.Println("Starting rezension monolith") + log.Log.Info("Starting rezension monolith") // Startwebsrver router := goji.NewMux() - http_api.BindAPI(router) + web.BindAPI(router) srv := &http.Server{ Addr: config.WebserverBind, Handler: router, @@ -53,5 +45,5 @@ func main() { // Stop services srv.Close() - log.Println("received", sig) + log.Log.Info("received", sig) } diff --git a/http/status.go b/http/status.go index 3d87239..0f1114d 100644 --- a/http/status.go +++ b/http/status.go @@ -3,11 +3,12 @@ package http import ( "net/http" - "github.com/genofire/hs_master-kss-monolith/lib" + lib "github.com/genofire/hs_master-kss-monolith/lib/http" + logger "github.com/genofire/hs_master-kss-monolith/lib/log" ) func statusHandler(w http.ResponseWriter, r *http.Request) { - log := lib.LogHTTP(r) + log := logger.HTTP(r) lib.Write(w, "running") log.Info("show status") } diff --git a/lib/http.go b/lib/http/main.go similarity index 98% rename from lib/http.go rename to lib/http/main.go index 19bc43c..c4784c5 100644 --- a/lib/http.go +++ b/lib/http/main.go @@ -1,4 +1,4 @@ -package lib +package http import ( "encoding/json" diff --git a/lib/http_test.go b/lib/http/main_test.go similarity index 98% rename from lib/http_test.go rename to lib/http/main_test.go index c294a93..6689c61 100644 --- a/lib/http_test.go +++ b/lib/http/main_test.go @@ -1,4 +1,4 @@ -package lib +package http import ( "bytes" diff --git a/lib/log.go b/lib/log/main.go similarity index 61% rename from lib/log.go rename to lib/log/main.go index a67a45a..95869ca 100644 --- a/lib/log.go +++ b/lib/log/main.go @@ -1,4 +1,4 @@ -package lib +package log import ( "log" @@ -11,16 +11,12 @@ var Log *logger.Logger func init(){ Log = logger.New() + // Enable fallback if core logger is used: log.SetOutput(Log.Writer()) } -func LogTimestamp(value bool) { - logger.SetFormatter(&logger.TextFormatter{ - DisableTimestamp: !value, - }) -} -// LogHTTP to add information of a httprequest to log -func LogHTTP(r *http.Request) *logger.Entry { +// HTTP to add information of a httprequest to log +func HTTP(r *http.Request) *logger.Entry { ip := r.Header.Get("X-Forwarded-For") if len(ip) <= 1 { ip = r.RemoteAddr diff --git a/lib/log_test.go b/lib/log/main_test.go similarity index 81% rename from lib/log_test.go rename to lib/log/main_test.go index 3cb2baf..3c54f61 100644 --- a/lib/log_test.go +++ b/lib/log/main_test.go @@ -1,4 +1,4 @@ -package lib +package log import ( "net/http" @@ -10,11 +10,8 @@ import ( func TestLog(t *testing.T) { assertion := assert.New(t) - // No values check, just if it crashed or not - LogTimestamp(false) - req, _ := http.NewRequest("GET", "https://google.com/lola/duda?q=wasd", nil) - log := LogHTTP(req) + log := HTTP(req) _, ok := log.Data["remote"] assertion.NotNil(ok, "remote address not set in logger")