Documentation
¶
Overview ¶
Package patch implements RFC 6902 (JSON Patch) and RFC 7396 (JSON Merge Patch) for use in HTTP PATCH handlers per RFC 5789.
Index ¶
Constants ¶
View Source
const ( ContentTypeMergePatch = "application/merge-patch+json" // RFC 7396 ContentTypeJSONPatch = "application/json-patch+json" // RFC 6902 )
View Source
const AcceptPatch = ContentTypeMergePatch + ", " + ContentTypeJSONPatch
AcceptPatch is the value for the Accept-Patch response header (RFC 5789 Section 3.1).
Variables ¶
View Source
var ( // ErrUnsupportedContentType should map to 415 with an Accept-Patch header. ErrUnsupportedContentType = errors.New("unsupported patch content type: use application/merge-patch+json (RFC 7396) or application/json-patch+json (RFC 6902)") // ErrInvalidPatch should map to 422 Unprocessable Entity. ErrInvalidPatch = errors.New("invalid patch document") )
Functions ¶
func Apply ¶
Apply applies a patch to a raw JSON document. Both formats are applied atomically (RFC 5789 Section 2).
func ApplyTo ¶
ApplyTo applies a patch directly to a Go struct. On error the target is left unchanged.
Types ¶
type Operation ¶
type Operation struct {
Op OpType
Path []string // Target path segments, e.g. ["address", "zip"]
From []string // Source path for move/copy (RFC 6902 only)
Value any // Value to set/add/test. Nil for remove.
}
Operation is a single parsed patch instruction.
Click to show internal directories.
Click to hide internal directories.