Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Any ¶
func Any(paths ...string) *anyMatcher
Any matcher acts as a placeholder for any value
It replaces any targeted path with a placeholder string
Any("user.name")
// or with multiple paths
Any("user.name", "user.email")
func Custom ¶
func Custom(path string, callback CustomCallback) *customMatcher
Custom matcher allows you to bring your own validation and placeholder value.
match.Custom("user.age", func(val any) (any, error) {
age, ok := val.(float64)
if !ok {
return nil, fmt.Errorf("expected number but got %T", val)
}
return "some number", nil
})
The callback func value for JSON can be on of these types:
bool // for JSON booleans
float64 // for JSON numbers
string // for JSON string literals
nil // for JSON null
map[string]any // for JSON objects
[]any // for JSON arrays
Types ¶
type CustomCallback ¶
type JSONMatcher ¶
type JSONMatcher interface {
JSON([]byte) ([]byte, []MatcherError)
}
type MatcherError ¶
internal Error struct returned from Matchers
Click to show internal directories.
Click to hide internal directories.