本文整理匯總了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})
}
}
示例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))
})