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