当前位置: 首页>>代码示例>>Golang>>正文


Golang gojsonschema.ResultError类代码示例

本文整理汇总了Golang中github.com/xeipuuv/gojsonschema.ResultError的典型用法代码示例。如果您正苦于以下问题:Golang ResultError类的具体用法?Golang ResultError怎么用?Golang ResultError使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ResultError类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 ""
}
开发者ID:datawolf,项目名称:libcompose,代码行数:26,代码来源:validation.go

示例2: unsupportedConfigMessage

func unsupportedConfigMessage(key string, nextErr gojsonschema.ResultError) string {
	service := serviceNameFromErrorField(nextErr.Field())

	message := fmt.Sprintf("Unsupported config option for %s service: '%s'", service, key)
	if val, ok := dockerConfigHints[key]; ok {
		message += fmt.Sprintf(" (did you mean '%s'?)", val)
	}

	return message
}
开发者ID:datawolf,项目名称:libcompose,代码行数:10,代码来源:validation.go

示例3: invalidTypeMessage

func invalidTypeMessage(service, key string, err gojsonschema.ResultError) string {
	expectedTypesString := err.Details()["expected"].(string)
	var expectedTypes []string

	if strings.Contains(expectedTypesString, ",") {
		expectedTypes = strings.Split(expectedTypesString[1:len(expectedTypesString)-1], ",")
	} else {
		expectedTypes = []string{expectedTypesString}
	}

	validTypesMsg := addArticle(strings.Join(expectedTypes, " or "))

	return fmt.Sprintf("Service '%s' configuration key '%s' contains an invalid type, it should be %s.", service, key, validTypesMsg)
}
开发者ID:datawolf,项目名称:libcompose,代码行数:14,代码来源:validation.go

示例4: 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
}
开发者ID:docker,项目名称:docker,代码行数:18,代码来源:schema.go

示例5: 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()
}
开发者ID:docker,项目名称:docker,代码行数:9,代码来源:schema.go

示例6: specificity

func specificity(err gojsonschema.ResultError) int {
	return len(strings.Split(err.Field(), "."))
}
开发者ID:docker,项目名称:docker,代码行数:3,代码来源:schema.go

示例7: containsTypeError

func containsTypeError(resultError gojsonschema.ResultError) bool {
	contextSplit := strings.Split(resultError.Context().String(), ".")
	_, err := strconv.Atoi(contextSplit[len(contextSplit)-1])
	return err == nil
}
开发者ID:datawolf,项目名称:libcompose,代码行数:5,代码来源:validation.go


注:本文中的github.com/xeipuuv/gojsonschema.ResultError类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。