Documentation
¶
Index ¶
- func EqualJSON(a, b string) (bool, error)
- func Sort(v interface{})
- type RecursiveSort
- type TypePriorityLookup
- func (lookup *TypePriorityLookup) CompareTypes(iv, jv reflect.Value) bool
- func (lookup *TypePriorityLookup) CompareUnknownTypes(iv, jv reflect.Value) bool
- func (lookup TypePriorityLookup) FromTypes(order ...reflect.Type) *TypePriorityLookup
- func (lookup TypePriorityLookup) FromValues(order ...interface{}) *TypePriorityLookup
- type TypePriorityLookupHelper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EqualJSON ¶
EqualJSON checks if two JSON strings are equal, ignoring the order of values.
Strings `a` and `b` are first unmarshaled into a JSON `interface{}`. Then, they are recursively sorted and compared using `reflect.DeepEqual`
If values differ or cannot be parsed, `false` is returned and `err != nil` describes the error. Otherwise, `true` and `nil` is returned.
If you wish to compare for equality in a different way, e.g. using github.com/google/go-cmp/cmp, you can easily reimplement this method yourself.
Types ¶
type RecursiveSort ¶
type RecursiveSort struct { TypePriorityLookupHelper // MapSortKey specifies the key of maps to use as the sorting key if available MapSortKey interface{} // StructSortField specifies the field of structs to use as the sorting key if available StructSortField string // Strict forces using `StructSortField` and `MapSortKey`. // // Note: if the key or field does not exist, this will panic. Strict bool }
RecursiveSort implements a recursive sort interface for arbitrary types.
func (*RecursiveSort) Sort ¶
func (rec *RecursiveSort) Sort(v interface{})
Sort recursively sorts an interface.
type TypePriorityLookup ¶
TypePriorityLookup maps types to integer priorities.
func (*TypePriorityLookup) CompareTypes ¶
func (lookup *TypePriorityLookup) CompareTypes(iv, jv reflect.Value) bool
CompareTypes compars two known types based on their priorities.
If priorities are not known, it delegates to `CompareUnknownTypes`.
func (*TypePriorityLookup) CompareUnknownTypes ¶
func (lookup *TypePriorityLookup) CompareUnknownTypes(iv, jv reflect.Value) bool
CompareUnknownTypes compares two types, of which at least one is not known, based on their string name.
func (TypePriorityLookup) FromTypes ¶
func (lookup TypePriorityLookup) FromTypes(order ...reflect.Type) *TypePriorityLookup
FromTypes builds a `TypePriorityLookup` priority lookup table based on the order of the passed types
func (TypePriorityLookup) FromValues ¶
func (lookup TypePriorityLookup) FromValues(order ...interface{}) *TypePriorityLookup
FromValues builds a `TypePriorityLookup` priority lookup table based on the order of the passed values