Documentation ¶
Index ¶
- Variables
- func Clone(doc interface{}) (ret interface{}, err error)
- func CompareValues(from Cursor, field string, value json.RawMessage) (retMatches, retMismatch int, err error)
- func ExtractValues(from Cursor, field string, del bool) (ret []interface{}, err error)
- func InsertValues(to Cursor, field string, vals []interface{}) (ret int, err error)
- func Jstr(s string) (ret interface{})
- func ReplaceValues(from Cursor, field string, msg json.RawMessage) (ret int, err error)
- type Copy
- type Cursor
- type Migration
- type Move
- type PatchCommand
- type Patches
- type Path
- type Remove
- type Replace
- type Target
- type Test
- type UnknownKey
Constants ¶
This section is empty.
Variables ¶
var EscapeHTML = false
EscapeHTML - replace &, >, and < with unicode sequences when copying / comparing strings? ( default for jsonpatch is not )
Functions ¶
func Clone ¶
func Clone(doc interface{}) (ret interface{}, err error)
Clone copies an in-memory json document. ( so we don't accidentally share objects which might later need separate, unique, transformations. )
func CompareValues ¶
func CompareValues(from Cursor, field string, value json.RawMessage) (retMatches, retMismatch int, err error)
CompareValues compares a path against raw json bytes; FIX: it's currently untested. ( This is normally used via patch commands. )
func ExtractValues ¶
ExtractValues of the named fields within the objects selected by the passed cursor. If del is true it will remove those elements from the document. ( This is normally used via patch commands. )
func InsertValues ¶
InsertValues puts the passed values into the targeted objects; the values are not cloned. The number of source and target values must match; returns the number of successful replications. ( This is normally used via patch commands. )
func Jstr ¶
func Jstr(s string) (ret interface{})
Jstr turns a string into json data ( for writing patches in go. ) FIX: restore the example.
func ReplaceValues ¶
ReplaceValues adds the passed raw json to the 'field' of objects selected by the passed cursor. ( This is normally used via patch commands. )
Types ¶
type Cursor ¶
type Cursor struct {
// contains filtered or unexported fields
}
Cursor reads (caches) a collection of objects from a json docs.
type PatchCommand ¶
type PatchCommand struct {
Migration // pointer to the command
}
PatchCommand holds a single command for the purpose of de/serializing a migration.
func (*PatchCommand) UnmarshalJSON ¶
func (c *PatchCommand) UnmarshalJSON(data []byte) (err error)
UnmarshalJSON creates concrete implementations of migrations.
type Patches ¶
type Patches []PatchCommand
Patches - a Migration - runs a series of other migrations.
func (Patches) ApplyOverMatches ¶
ApplyOverMatches runs this series of operations over all objects matched by the passed cursor.
type Path ¶
type Path string
Path provides a JSONPath ready string. See: https://goessner.net/articles/JsonPath/, and https://github.com/PaesslerAG/
type Remove ¶
type Remove struct {
Path Target `json:"path"`
}
Remove - a Migration - deletes pieces of a document.
type Replace ¶
type Replace struct { Path Target `json:"path"` Value json.RawMessage `json:"value"` }
Replace - a Migration - substitutes new values for pieces of a document.
type Target ¶
type Target struct { Parent Path `json:"parent"` Field string `json:"field"` FullPath Path // original path, the join of parent and field. }
Target a location in a json document with a json path pointing to (one or more) objects, and a field addressing a member of each objects.
func (*Target) UnmarshalJSON ¶
UnmarshalJSON creates concrete implementations of migrations.
type Test ¶
type Test struct { Path Target `json:"path"` Value json.RawMessage `json:"value,omitempty"` Patches Patches `json:"patches,omitempty"` SubPatches Patches `json:"subpatches,omitempty"` }
Test - a Migration - validates pieces of a document, then possibly runs sub matches. Patches are run against the current document, and not specifically things matched by the test. SubPatches are run against all elements matched by the test.
type UnknownKey ¶
type UnknownKey struct {
// contains filtered or unexported fields
}
UnknownKey replaces jsonpath's string error for key not found.
func (UnknownKey) Error ¶
func (e UnknownKey) Error() string