MCPcopy Create free account
hub / github.com/rabbitstack/fibratus / validate

Function validate

pkg/config/validation.go:27–43  ·  view source on GitHub ↗
(s string, m interface{})

Source from the content-addressed store, hash-verified

25)
26
27func validate(s string, m interface{}) (bool, []error) {
28 converted, err := convertToStringKeysRecursive(m, "")
29 if err != nil {
30 return false, []error{fmt.Errorf("fail to convert keys to string: %v", err)}
31 }
32 loader := gojsonschema.NewGoLoader(converted)
33 sc := gojsonschema.NewStringLoader(s)
34 r, err := gojsonschema.Validate(sc, loader)
35 if err != nil {
36 return false, []error{fmt.Errorf("fail to validate file through schema: %v", err)}
37 }
38 errs := make([]error, len(r.Errors()))
39 for i, err := range r.Errors() {
40 errs[i] = errors.New(err.String())
41 }
42 return r.Valid(), errs
43}
44
45// convertToStringKeysRecursive ensures keys are converted to strings for jsonschema.
46func convertToStringKeysRecursive(value interface{}, keyPrefix string) (interface{}, error) {

Callers 4

TestValidateFunction · 0.70
ValidateMethod · 0.70
LoadMacrosMethod · 0.70
decodeFilterFunction · 0.70

Calls 5

ValidMethod · 0.80
ErrorsMethod · 0.65
StringMethod · 0.65
ValidateMethod · 0.45

Tested by 1

TestValidateFunction · 0.56