err.Context(): gojsonschema.jsonContext Returns the context. This has a String() method that will print something like this: (root).firstName
err.Field(): string Returns the fieldname in the format firstName, or for embedded properties, person.firstName. This returns the same as the String() method on err.Context() but removes the (root). prefix.
err.Description(): string The error description. This is based on the locale you are using. See the beginning of this section for overwriting the locale with a custom implementation.
err.Details(): gojsonschema.ErrorDetails Returns a map[string]interface{} of additional error details specific to the error. For example, GTE errors will have a "min" value, LTE will have a "max" value. See errors.go for a full description of all the error details. Every error always contains a "field" key that holds the value of err.Field()
Note in most cases, the err.Details() will be used to generate replacement strings in your locales, and not used directly. These strings follow the text/template format i.e.
{{.field}} must be greater than or equal to {{.min}}
Formats
JSON Schema allows for optional "format" property to validate strings against well-known formats. gojsonschema ships with all of the formats defined in the spec that you can use like this:
{"type": "string","format": "email"}
Available formats: date-time, hostname, email, ipv4, ipv6, uri.
For repetitive or more complex formats, you can create custom format checkers and add them to gojsonschema like this:
// Define the format checkertypeRoleFormatCheckerstruct {}// Ensure it meets the gojsonschema.FormatChecker interfacefunc (f RoleFormatChecker) IsFormat(input string) bool {return strings.HasPrefix("ROLE_", input)}// Add it to the librarygojsonschema.FormatCheckers.Add("role", RoleFormatChecker{})`