Documentation
¶
Index ¶
- Constants
- type Operation
- type Patch
- type Pointer
- func (p Pointer) Append(frag string) Pointer
- func (p Pointer) Chop() (string, Pointer)
- func (a Pointer) Contains(b Pointer) bool
- func (p Pointer) Copy(from interface{}, at Pointer) (interface{}, error)
- func (p Pointer) Get(from interface{}) (interface{}, error)
- func (p Pointer) MarshalJSON() ([]byte, error)
- func (p Pointer) Move(from interface{}, at Pointer) (interface{}, error)
- func (p Pointer) Put(to interface{}, val interface{}) (interface{}, error)
- func (p *Pointer) Remove(from interface{}) (interface{}, error)
- func (p Pointer) Replace(to interface{}, val interface{}) (interface{}, error)
- func (p Pointer) Shift() (string, Pointer)
- func (p Pointer) String() string
- func (p *Pointer) Test(from interface{}, sample interface{}) error
- func (p *Pointer) UnmarshalJSON(buf []byte) error
Constants ¶
const ContentType = "application/json-patch+json"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Operation ¶
type Operation struct { // Op can be one of: // * "add" // * "remove" // * "replace" // * "move" // * "copy" // * "test" // All Operations must have an Op. Op string `json:"op"` // Path is a JSON Pointer as defined in RFC 6901 // All Operations must have a Path Path string `json:"path"` // From is a JSON pointer indicating where a value should be // copied/moved from. From is only used by copy and move operations. From string `json:"from"` // Value is the Value to be used for add, replace, and test operations. Value interface{} `json:"value"` // contains filtered or unexported fields }
operation represents a valid JSON Patch operation as defined by RFC 6902
func (*Operation) UnmarshalJSON ¶
type Patch ¶
type Patch []Operation
Patch is an array of individual JSON Patch operations.
func Generate ¶
Generate generates a JSON Patch that will modify base into target. If paranoid is true, then the generated patch with have test checks for changed item.
base and target must be byte arrays containing valid JSON
func GenerateFull ¶
Generate generates a JSON Patch that will modify base into target. If paranoid is true, then the generated patch with have test checks for changed item. If pretest is true, then the generated patch with have test ALL parts of the base.
base and target must be byte arrays containing valid JSON
type Pointer ¶
type Pointer []pointerSegment
Pointer is a JSON Pointer
func NewPointer ¶
newpointer takes a string that conforms to RFC6901 and turns it into a JSON pointer.
func (Pointer) Chop ¶
Chop extracts the last element in the pointer, returning it and the rest of the pointer.
func (Pointer) Copy ¶
Copy deep-copies the value pointed to by p in from to the location pointed to by at.
func (Pointer) Get ¶
Get takes an unmarshalled JSON blob, and returns the value pointed at by the pointer. The unmarshalled blob is left unchanged.
func (Pointer) MarshalJSON ¶
Allow a pointer to be marshalled to valid JSON.
func (Pointer) Move ¶
Move moves the value pointed to by p in from to the location pointed to by at.
func (Pointer) Put ¶
Put puts val into to at the position indicated by the pointer, returning a possibly new value for to. The position does not have to already exist or refer to a preexisting Value.
Put may have to return a new to if to happens to be a slice, since the semantics of Put necessarily involve growing the Slice.
func (*Pointer) Remove ¶
Remove removes the value pointed to by the pointer from from, returning a possibly new value for from.
Remove may have to return a new from if it is a slice, because the semantics for Reomve on a Slice involve shrinking it, which involves reallocation the way we do it.
func (Pointer) Shift ¶
Shift extracts the first element in the pointer, returning it and the rest of the pointer.
func (*Pointer) UnmarshalJSON ¶
Allow unmarshalling from JSON