Base Project
This commit is contained in:
10
internal/middlewares/auth_middleware.go
Normal file
10
internal/middlewares/auth_middleware.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package middlewares
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func AuthMiddleware() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
// 1. Get the Authorization header
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
34
internal/middlewares/logging_middleware.go
Normal file
34
internal/middlewares/logging_middleware.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func LoggingMiddleware() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
start := time.Now()
|
||||
|
||||
log.Info().
|
||||
Str("type", "request").
|
||||
Str("method", c.Request.Method).
|
||||
Str("path", c.Request.URL.Path).
|
||||
Str("ip", c.ClientIP()).
|
||||
Str("query", c.Request.URL.RawQuery).
|
||||
Time("time", start).
|
||||
Msg("incoming request")
|
||||
|
||||
c.Next()
|
||||
|
||||
log.Info().
|
||||
Str("type", "response").
|
||||
Str("method", c.Request.Method).
|
||||
Str("path", c.Request.URL.Path).
|
||||
Int("status", c.Writer.Status()).
|
||||
Dur("latency", time.Since(start)).
|
||||
Time("time", time.Now()).
|
||||
Msg("outgoing response")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user