Files
slog-gin/dump.go
T
Samuel Berthe 3136afbcb0 feat: max size (#6)
for http body dump
2023-10-18 02:49:27 +02:00

32 lines
581 B
Go

package sloggin
import (
"bytes"
"github.com/gin-gonic/gin"
)
type bodyWriter struct {
gin.ResponseWriter
body *bytes.Buffer
maxSize int
}
// implements gin.ResponseWriter
func (w bodyWriter) Write(b []byte) (int, error) {
if w.body.Len()+len(b) > w.maxSize {
w.body.Write(b[:w.maxSize-w.body.Len()])
} else {
w.body.Write(b)
}
return w.ResponseWriter.Write(b)
}
func newBodyWriter(writer gin.ResponseWriter, maxSize int) *bodyWriter {
return &bodyWriter{
body: bytes.NewBufferString(""),
ResponseWriter: writer,
maxSize: maxSize,
}
}