mirror of
https://github.com/pikami/cosmium.git
synced 2025-12-19 17:00:37 +00:00
Move out repository models; Hidrate collection on create
This commit is contained in:
30
api/handlers/middleware/loggers.go
Normal file
30
api/handlers/middleware/loggers.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func RequestLogger() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
buf, _ := io.ReadAll(c.Request.Body)
|
||||
rdr1 := io.NopCloser(bytes.NewBuffer(buf))
|
||||
rdr2 := io.NopCloser(bytes.NewBuffer(buf))
|
||||
|
||||
fmt.Println(readBody(rdr1))
|
||||
|
||||
c.Request.Body = rdr2
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
func readBody(reader io.Reader) string {
|
||||
buf := new(bytes.Buffer)
|
||||
buf.ReadFrom(reader)
|
||||
|
||||
s := buf.String()
|
||||
return s
|
||||
}
|
||||
Reference in New Issue
Block a user