當前位置: 首頁>>代碼示例>>Golang>>正文


Golang AttributeDefinition.Validations方法代碼示例

本文整理匯總了Golang中github.com/raphael/goa/design.AttributeDefinition.Validations方法的典型用法代碼示例。如果您正苦於以下問題:Golang AttributeDefinition.Validations方法的具體用法?Golang AttributeDefinition.Validations怎麽用?Golang AttributeDefinition.Validations使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/raphael/goa/design.AttributeDefinition的用法示例。


在下文中一共展示了AttributeDefinition.Validations方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Required

// Required adds a "required" validation to the attribute.
// See http://json-schema.org/latest/json-schema-validation.html#anchor61.
func Required(names ...string) {
	var at *design.AttributeDefinition
	if a, ok := attributeDefinition(false); ok {
		at = a
	} else if mt, ok := mediaTypeDefinition(true); ok {
		at = mt.AttributeDefinition
	} else {
		return
	}
	if at.Type != nil && at.Type.Kind() != design.ObjectKind {
		incompatibleAttributeType("required", at.Type.Name(), "an object")
	} else {
		at.Validations = append(at.Validations, &design.RequiredValidationDefinition{Names: names})
	}
}
開發者ID:harboe,項目名稱:goa,代碼行數:17,代碼來源:attribute.go

示例2:

		codegen.TempCount = 0
	})

	Describe("ValidationChecker", func() {
		Context("given an attribute definition and validations", func() {
			var attType design.DataType
			var validations []design.ValidationDefinition

			att := new(design.AttributeDefinition)
			target := "val"
			context := "context"
			var code string // generated code

			JustBeforeEach(func() {
				att.Type = attType
				att.Validations = validations
				code = codegen.ValidationChecker(att, false, false, target, context, 1)
			})

			Context("of enum", func() {
				BeforeEach(func() {
					attType = design.Integer
					enumVal := &design.EnumValidationDefinition{
						Values: []interface{}{1, 2, 3},
					}
					validations = []design.ValidationDefinition{enumVal}
				})

				It("produces the validation go code", func() {
					Ω(code).Should(Equal(enumValCode))
				})
開發者ID:derekperkins,項目名稱:goa,代碼行數:31,代碼來源:validation_test.go


注:本文中的github.com/raphael/goa/design.AttributeDefinition.Validations方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。