-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent.go
More file actions
29 lines (25 loc) · 901 Bytes
/
event.go
File metadata and controls
29 lines (25 loc) · 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package gauzer
import "log/slog"
// DiagnosticEvent is the structured payload emitted on every validation failure.
// Value is always a stringified, truncated copy of the failing input — never `any` —
// to prevent PII leaks and log-bloat in cloud billing.
type DiagnosticEvent struct {
Field string
Constraint string
Value string // stringified & truncated by the Rule, max 64 chars
ValueType string // e.g. "string", "int", "unknown"
Message string
}
// Error implements the standard error interface.
func (e DiagnosticEvent) Error() string {
return e.Message
}
// LogValue implements slog.LogValuer so the event nests under "err" in JSON output.
func (e DiagnosticEvent) LogValue() slog.Value {
return slog.GroupValue(
slog.String("field", e.Field),
slog.String("constraint", e.Constraint),
slog.String("value", e.Value),
slog.String("type", e.ValueType),
)
}