first commit
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const maxBodyLength = 2000
|
||||
|
||||
// RequestLog stores a minimal record of every proxied request.
|
||||
// Sensitive headers (e.g. Authorization) are NEVER stored verbatim.
|
||||
type RequestLog struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
Endpoint string `gorm:"size:512" json:"endpoint"`
|
||||
Method string `gorm:"size:16" json:"method"`
|
||||
ClientIP string `gorm:"size:64" json:"client_ip"`
|
||||
RequestBody string `gorm:"type:text" json:"request_body"`
|
||||
ResponseStatus int `json:"response_status"`
|
||||
LatencyMs int64 `json:"latency_ms"`
|
||||
}
|
||||
|
||||
// TruncateBody returns at most maxBodyLength characters from body.
|
||||
func TruncateBody(body string) string {
|
||||
if len(body) <= maxBodyLength {
|
||||
return body
|
||||
}
|
||||
return body[:maxBodyLength] + "…[truncated]"
|
||||
}
|
||||
Reference in New Issue
Block a user