Documentation ¶
Index ¶
- Constants
- type CustomEqualFunc
- type DiffList
- type Differ
- func (d *Differ) AddCoerceNull(dest ruleDest, selector *regexp.Regexp) *Differ
- func (d *Differ) AddCustomEqual(selector *regexp.Regexp, fn CustomEqualFunc) *Differ
- func (d *Differ) AddFloatEqual(selector *regexp.Regexp, fn FloatEqualFunc) *Differ
- func (d *Differ) AddIgnore(dest ruleDest, selector *regexp.Regexp) *Differ
- func (d *Differ) AddIgnoreIfZero(dest ruleDest, selector *regexp.Regexp) *Differ
- func (d *Differ) AddIgnoreOrder(selector *regexp.Regexp) *Differ
- func (d *Differ) AddStringNumber(selector *regexp.Regexp) *Differ
- func (d *Differ) Diff(jsonA, jsonB string) (DiffList, error)
- type FloatEqualFunc
- type SingleDiff
Constants ¶
const ( RuleA ruleDest = iota RuleB RuleAB )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CustomEqualFunc ¶
CustomeEqualFn is a function implementing custom comparsion for a selector and two *obj.Value. If this matches, then
- all other rules does not apply
- jf will stop the recursion to items below
- if applied on items with ignored order, then selector matches either jsonA, either jsonB
type DiffList ¶
type DiffList []SingleDiff
type Differ ¶
type Differ struct {
// contains filtered or unexported fields
}
Differ traverse through JSONS and diff each part. It stores actual differences and can apply rules to different parts for comparison
func NewDiffer ¶
func NewDiffer() *Differ
NewDiffer creates new empty differ with no rules. It can get additional processing rules via AddXYZ methods
func (*Differ) AddCoerceNull ¶
AddCoerceNull enables coercion of null value to empty value for given type "key": null will be equivalent of {}, [], "", 0 and false
func (*Differ) AddCustomEqual ¶
func (d *Differ) AddCustomEqual(selector *regexp.Regexp, fn CustomEqualFunc) *Differ
AddCustomEqualFunc adds a function for comparing custom values. Note this function is special and precedes all the other rules except ignore order for arrays. In this specific case provided JSON Path selector applies to jsonA or jsonB
func (*Differ) AddFloatEqual ¶
func (d *Differ) AddFloatEqual(selector *regexp.Regexp, fn FloatEqualFunc) *Differ
AddFloatEqual adds a function for comparing floats. Default function expects numbers to be the same up to 1e-9
func (*Differ) AddIgnoreIfZero ¶
AddIgnoreIfEmpty adds selectors, which will be ignored in a case value is empty
func (*Differ) AddIgnoreOrder ¶
AddIgnoreRule ignores order of arrays, so [1, 2, 3] == [3, 2, 1]
func (*Differ) AddStringNumber ¶
AddStringNumber equals "1" == 1
type FloatEqualFunc ¶
FloatEqualFn is a function comparing two floats
type SingleDiff ¶
type SingleDiff struct {
// contains filtered or unexported fields
}
SingleDiff express the difference of one JSON selector
func (*SingleDiff) A ¶
func (d *SingleDiff) A() string
func (*SingleDiff) B ¶
func (d *SingleDiff) B() string
func (*SingleDiff) Selector ¶
func (d *SingleDiff) Selector() string