Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrCannotTrim indicates the JSON couldn't be reduced below limits. ErrCannotTrim = errors.New("cannot trim JSON below limits") // Marker is the value used when ReplaceWithMarker is true. Marker = "[TRIMMED]" )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
FieldLimit int // Max bytes per field/object/array (default: 500)
TotalLimit int // Max total output bytes (default: 1024)
Blacklist []string // Paths to exclude. Supports wildcards (e.g., "users.*.email")
Strategy TruncStrategy // Removal order during total enforcement (default: RemoveLargest)
MaxDepth int // Recursion depth limit (default: 10)
TruncateStrings bool // Truncate long strings with "..." instead of dropping (default: false)
ReplaceWithMarker bool // If true, replaced fields become "[TRIMMED]" instead of being deleted
Hooks Hooks // Optional pre/post callbacks
}
Config holds customization options for the Trimmer.
type FIFO ¶
type FIFO struct{}
Built-in strategies.
func (FIFO) SelectNextToRemove ¶
SelectNextToRemove for FIFO: First key or index 0.
type Hooks ¶
type Hooks struct {
PreTrim func(v interface{}) interface{}
PostTrim func(v interface{}, err error) interface{}
}
Hooks for extensibility.
type PrioritizeKeys ¶
type PrioritizeKeys struct {
KeepKeys []string
Fallback TruncStrategy
}
Built-in strategies.
func (PrioritizeKeys) SelectNextToRemove ¶
func (s PrioritizeKeys) SelectNextToRemove(v interface{}) string
SelectNextToRemove for PrioritizeKeys: Skips keep keys, falls back.
type RemoveLargest ¶
type RemoveLargest struct{}
Built-in strategies.
func (RemoveLargest) SelectNextToRemove ¶
func (s RemoveLargest) SelectNextToRemove(v interface{}) string
SelectNextToRemove for RemoveLargest: Finds the largest by approximate size.
type Trimmer ¶
type Trimmer struct {
// contains filtered or unexported fields
}
Trimmer is the main struct.
type TruncStrategy ¶
type TruncStrategy interface {
// SelectNextToRemove identifies the next field/item to drop.
// Returns key (map) or "idx:N" (array). Empty string if done.
SelectNextToRemove(v interface{}) string
}
TruncStrategy defines removal policies for EnforceTotalLimit.
Click to show internal directories.
Click to hide internal directories.