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", "user.email") // or for yaml 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 one 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 The callback func value for YAML can be one of these types: bool // for YAML booleans float64 // for YAML float numbers uint64 // for YAML integer numbers string // for YAML string literals nil // for YAML null map[string]any // for YAML objects []any // for YAML arrays
Types ¶
type CustomCallback ¶
type JSONMatcher ¶
type JSONMatcher interface {
JSON([]byte) ([]byte, []MatcherError)
}
type MatcherError ¶
internal Error struct returned from Matchers
type YAMLMatcher ¶ added in v0.5.8
type YAMLMatcher interface {
YAML([]byte) ([]byte, []MatcherError)
}
Click to show internal directories.
Click to hide internal directories.