Documentation
¶
Overview ¶
Package delta provides a generic, reflection-based HTTP PATCH engine for Go structs.
It supports partial updates (key present = update, key absent = leave, null = reset), field include/exclude lists, deep cloning with pointer identity on the original, change tracking, diffing, and opt-in operation wrappers for fine-grained map and slice control.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ApplyOption ¶
type ApplyOption func(*options)
ApplyOption configures a single Apply call.
func ExcludeFields ¶
func ExcludeFields(fields ...string) ApplyOption
ExcludeFields blocks these fields from being patched (by json tag name). Combined with IncludeFields: effective = include ∩ complement(exclude).
func IncludeFields ¶
func IncludeFields(fields ...string) ApplyOption
IncludeFields restricts the patch to only these fields (by json tag name). Combined with ExcludeFields: effective = include ∩ complement(exclude).
type ApplyResult ¶
type ApplyResult[T any] struct { // Original is the same pointer passed to Apply — never mutated. Original *T // Object is a freshly allocated deep-clone of Original with changes applied. Object *T // UpdatedFields lists json tag names of fields whose value actually changed. UpdatedFields []string }
ApplyResult is returned by Patch.Apply.
func (ApplyResult[T]) Diff ¶
func (r ApplyResult[T]) Diff() []FieldDiff
Diff returns a flat list of old/new values for each field in UpdatedFields. Reflects into Original and Object — both must be non-nil.
type Patch ¶
type Patch[T any] struct { // contains filtered or unexported fields }
Patch is the entry point for applying a PATCH payload to a value of type T. Constructed via NewPatch or NewPatchFromReader.
func NewPatch ¶
func NewPatch[T any](data []byte, opts ...PatchOption) (*Patch[T], error)
NewPatch parses a JSON PATCH body and constructs a Patch[T]. Returns an error if the body is not a valid JSON object, or if WithOperations is set and the payload contains invalid operation shapes.
func NewPatchFromReader ¶
NewPatchFromReader parses a JSON PATCH body from an io.Reader and constructs a Patch[T].
func (*Patch[T]) Apply ¶
func (p *Patch[T]) Apply(target *T, opts ...ApplyOption) (ApplyResult[T], error)
Apply deep-clones target, applies the patch, and returns the result. target is stored as Original (same pointer, never mutated). Object is a freshly allocated clone with changes applied.
type PatchOption ¶
type PatchOption func(*patchConfig)
PatchOption configures patch construction.
func WithOperations ¶
func WithOperations() PatchOption
WithOperations enables $set / $unset / $merge / $clear for maps and $add / $remove / $merge / $clear for slices. When enabled, the patch is validated at construction time — invalid operations for a given field type return an error from NewPatch.