Files
opantoantro/models/request_log.go
T
Beyhan Ogur a408821410 first commit
2026-05-11 15:08:50 +03:00

33 lines
1.0 KiB
Go

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]"
}