cleaned up the LogMiddleware
Dieser Commit ist enthalten in:
Ursprung
a69e026b70
Commit
ba2ed57968
|
@ -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()
|
||||
|
|
Laden…
In neuem Issue referenzieren