1
0
Fork 0

cleaned up the LogMiddleware

Dieser Commit ist enthalten in:
Sebastian Tobie 2021-01-19 00:18:08 +01:00
Ursprung a69e026b70
Commit ba2ed57968
1 geänderte Dateien mit 6 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -9,17 +9,14 @@ import (
"go.sebtobie.de/httpserver/auth" "go.sebtobie.de/httpserver/auth"
) )
// LogMiddleware is an middleware to log requests to phuslu/log and catches panics // LogMiddleware is an middleware to log requests to phuslu/log and catches panics.
// If it is added multiple times, only the first time sends entries to the log.
func LogMiddleware(c *gin.Context) { func LogMiddleware(c *gin.Context) {
var xid log.XID if _, exists := c.Get("xid"); exists {
var tmp interface{} return
var exists bool
if tmp, exists = c.Get("xid"); !exists {
xid = log.NewXIDWithTime(time.Now().UnixNano())
c.Set("xid", xid)
} else {
xid = tmp.(log.XID)
} }
var xid = log.NewXIDWithTime(time.Now().UnixNano())
c.Set("xid", xid)
defer func() { defer func() {
var entry = log.Info() var entry = log.Info()
int := recover() int := recover()