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"
)
// 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) {
var xid log.XID
var tmp interface{}
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)
if _, exists := c.Get("xid"); exists {
return
}
var xid = log.NewXIDWithTime(time.Now().UnixNano())
c.Set("xid", xid)
defer func() {
var entry = log.Info()
int := recover()