本文整理匯總了Golang中github.com/xeipuuv/gojsonschema.ResultError.Type方法的典型用法代碼示例。如果您正苦於以下問題:Golang ResultError.Type方法的具體用法?Golang ResultError.Type怎麽用?Golang ResultError.Type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/xeipuuv/gojsonschema.ResultError
的用法示例。
在下文中一共展示了ResultError.Type方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: oneOfMessage
func oneOfMessage(serviceMap RawServiceMap, schema map[string]interface{}, err, nextErr gojsonschema.ResultError) string {
switch nextErr.Type() {
case "additional_property_not_allowed":
property := nextErr.Details()["property"]
return fmt.Sprintf("contains unsupported option: '%s'", property)
case "invalid_type":
if containsTypeError(nextErr) {
expectedType := addArticle(nextErr.Details()["expected"].(string))
return fmt.Sprintf("contains %s, which is an invalid type, it should be %s", getValue(serviceMap, nextErr.Context().String()), expectedType)
}
validTypes := parseValidTypesFromSchema(schema, err.Context().String())
validTypesMsg := addArticle(strings.Join(validTypes, " or "))
return fmt.Sprintf("contains an invalid type, it should be %s", validTypesMsg)
case "unique":
contextWithDuplicates := getValue(serviceMap, nextErr.Context().String())
return fmt.Sprintf("contains non unique items, please remove duplicates from %s", contextWithDuplicates)
}
return ""
}
示例2: getDescription
func getDescription(err gojsonschema.ResultError) string {
if err.Type() == "invalid_type" {
if expectedType, ok := err.Details()["expected"].(string); ok {
return fmt.Sprintf("must be a %s", humanReadableType(expectedType))
}
}
return err.Description()
}
示例3: getMostSpecificError
func getMostSpecificError(errors []gojsonschema.ResultError) gojsonschema.ResultError {
var mostSpecificError gojsonschema.ResultError
for _, err := range errors {
if mostSpecificError == nil {
mostSpecificError = err
} else if specificity(err) > specificity(mostSpecificError) {
mostSpecificError = err
} else if specificity(err) == specificity(mostSpecificError) {
// Invalid type errors win in a tie-breaker for most specific field name
if err.Type() == "invalid_type" && mostSpecificError.Type() != "invalid_type" {
mostSpecificError = err
}
}
}
return mostSpecificError
}