本文整理汇总了Golang中github.com/raphael/goa.MissingAttributeError函数的典型用法代码示例。如果您正苦于以下问题:Golang MissingAttributeError函数的具体用法?Golang MissingAttributeError怎么用?Golang MissingAttributeError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MissingAttributeError函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewRateBottlePayload
// NewRateBottlePayload instantiates a RateBottlePayload from a raw request body.
// It validates each field and returns an error if any validation fails.
func NewRateBottlePayload(raw interface{}) (*RateBottlePayload, error) {
var err error
var p *RateBottlePayload
if val, ok := raw.(map[string]interface{}); ok {
p = new(RateBottlePayload)
if v, ok := val["rating"]; ok {
var tmp12 int
if f, ok := v.(float64); ok {
tmp12 = int(f)
} else {
err = goa.InvalidAttributeTypeError(`payload.Rating`, v, "int", err)
}
if err == nil {
if tmp12 < 1 {
err = goa.InvalidRangeError(`payload.Rating`, tmp12, 1, true, err)
}
if tmp12 > 5 {
err = goa.InvalidRangeError(`payload.Rating`, tmp12, 5, false, err)
}
}
p.Rating = tmp12
} else {
err = goa.MissingAttributeError(`payload`, "rating", err)
}
} else {
err = goa.InvalidAttributeTypeError(`payload`, raw, "map[string]interface{}", err)
}
return p, err
}
示例2: UnmarshalRateBottlePayload
// UnmarshalRateBottlePayload unmarshals and validates a raw interface{} into an instance of RateBottlePayload
func UnmarshalRateBottlePayload(source interface{}, inErr error) (target *RateBottlePayload, err error) {
err = inErr
if val, ok := source.(map[string]interface{}); ok {
target = new(RateBottlePayload)
if v, ok := val["rating"]; ok {
var tmp12 int
if f, ok := v.(float64); ok {
tmp12 = int(f)
} else {
err = goa.InvalidAttributeTypeError(`payload.Rating`, v, "int", err)
}
if err == nil {
if tmp12 < 1 {
err = goa.InvalidRangeError(`payload.Rating`, tmp12, 1, true, err)
}
if tmp12 > 5 {
err = goa.InvalidRangeError(`payload.Rating`, tmp12, 5, false, err)
}
}
target.Rating = tmp12
} else {
err = goa.MissingAttributeError(`payload`, "rating", err)
}
} else {
err = goa.InvalidAttributeTypeError(`payload`, source, "dictionary", err)
}
return
}
示例3: NewCreateSeriesPayload
// NewCreateSeriesPayload instantiates a CreateSeriesPayload from a raw request body.
// It validates each field and returns an error if any validation fails.
func NewCreateSeriesPayload(raw interface{}) (*CreateSeriesPayload, error) {
var err error
var p *CreateSeriesPayload
if val, ok := raw.(map[string]interface{}); ok {
p = new(CreateSeriesPayload)
if v, ok := val["name"]; ok {
var tmp3 string
if val, ok := v.(string); ok {
tmp3 = val
} else {
err = goa.InvalidAttributeTypeError(`payload.Name`, v, "string", err)
}
if err == nil {
if len(tmp3) < 2 {
err = goa.InvalidLengthError(`payload.Name`, tmp3, 2, true, err)
}
}
p.Name = tmp3
} else {
err = goa.MissingAttributeError(`payload`, "name", err)
}
} else {
err = goa.InvalidAttributeTypeError(`payload`, raw, "map[string]interface{}", err)
}
return p, err
}
示例4: NewCreateUserPayload
// NewCreateUserPayload instantiates a CreateUserPayload from a raw request body.
// It validates each field and returns an error if any validation fails.
func NewCreateUserPayload(raw interface{}) (*CreateUserPayload, error) {
var err error
var p *CreateUserPayload
if val, ok := raw.(map[string]interface{}); ok {
p = new(CreateUserPayload)
if v, ok := val["email"]; ok {
var tmp5 string
if val, ok := v.(string); ok {
tmp5 = val
} else {
err = goa.InvalidAttributeTypeError(`payload.Email`, v, "string", err)
}
if err == nil {
if len(tmp5) < 2 {
err = goa.InvalidLengthError(`payload.Email`, tmp5, 2, true, err)
}
}
p.Email = tmp5
}
if v, ok := val["first_name"]; ok {
var tmp6 string
if val, ok := v.(string); ok {
tmp6 = val
} else {
err = goa.InvalidAttributeTypeError(`payload.FirstName`, v, "string", err)
}
if err == nil {
if len(tmp6) < 2 {
err = goa.InvalidLengthError(`payload.FirstName`, tmp6, 2, true, err)
}
}
p.FirstName = tmp6
} else {
err = goa.MissingAttributeError(`payload`, "first_name", err)
}
if v, ok := val["last_name"]; ok {
var tmp7 string
if val, ok := v.(string); ok {
tmp7 = val
} else {
err = goa.InvalidAttributeTypeError(`payload.LastName`, v, "string", err)
}
if err == nil {
if len(tmp7) < 2 {
err = goa.InvalidLengthError(`payload.LastName`, tmp7, 2, true, err)
}
}
p.LastName = tmp7
}
} else {
err = goa.InvalidAttributeTypeError(`payload`, raw, "map[string]interface{}", err)
}
return p, err
}
示例5: UnmarshalCreateAccountPayload
// UnmarshalCreateAccountPayload unmarshals and validates a raw interface{} into an instance of CreateAccountPayload
func UnmarshalCreateAccountPayload(source interface{}, inErr error) (target *CreateAccountPayload, err error) {
err = inErr
if val, ok := source.(map[string]interface{}); ok {
target = new(CreateAccountPayload)
if v, ok := val["name"]; ok {
var tmp1 string
if val, ok := v.(string); ok {
tmp1 = val
} else {
err = goa.InvalidAttributeTypeError(`payload.Name`, v, "string", err)
}
target.Name = tmp1
} else {
err = goa.MissingAttributeError(`payload`, "name", err)
}
} else {
err = goa.InvalidAttributeTypeError(`payload`, source, "dictionary", err)
}
return
}
示例6: NewCreateAccountPayload
// NewCreateAccountPayload instantiates a CreateAccountPayload from a raw request body.
// It validates each field and returns an error if any validation fails.
func NewCreateAccountPayload(raw interface{}) (*CreateAccountPayload, error) {
var err error
var p *CreateAccountPayload
if val, ok := raw.(map[string]interface{}); ok {
p = new(CreateAccountPayload)
if v, ok := val["name"]; ok {
var tmp1 string
if val, ok := v.(string); ok {
tmp1 = val
} else {
err = goa.InvalidAttributeTypeError(`payload.Name`, v, "string", err)
}
p.Name = tmp1
} else {
err = goa.MissingAttributeError(`payload`, "name", err)
}
} else {
err = goa.InvalidAttributeTypeError(`payload`, raw, "map[string]interface{}", err)
}
return p, err
}
示例7:
Ω(tErr.Mesg).Should(ContainSubstring(expected))
})
})
})
var _ = Describe("MissingAttributeError", func() {
var valErr, err error
ctx := "ctx"
name := "param"
BeforeEach(func() {
err = nil
})
JustBeforeEach(func() {
valErr = goa.MissingAttributeError(ctx, name, err)
})
It("creates a multi error", func() {
Ω(valErr).ShouldNot(BeNil())
Ω(valErr).Should(BeAssignableToTypeOf(goa.MultiError{}))
mErr := valErr.(goa.MultiError)
Ω(mErr).Should(HaveLen(1))
Ω(mErr[0]).Should(BeAssignableToTypeOf(&goa.TypedError{}))
tErr := mErr[0].(*goa.TypedError)
Ω(tErr.ID).Should(Equal(goa.ErrorID((goa.ErrMissingAttribute))))
Ω(tErr.Mesg).Should(ContainSubstring(ctx))
Ω(tErr.Mesg).Should(ContainSubstring(name))
})
Context("with a pre-existing error", func() {
示例8: UnmarshalCreateBottlePayload
// UnmarshalCreateBottlePayload unmarshals and validates a raw interface{} into an instance of CreateBottlePayload
func UnmarshalCreateBottlePayload(source interface{}, inErr error) (target *CreateBottlePayload, err error) {
err = inErr
if val, ok := source.(map[string]interface{}); ok {
target = new(CreateBottlePayload)
if v, ok := val["color"]; ok {
var tmp3 string
if val, ok := v.(string); ok {
tmp3 = val
} else {
err = goa.InvalidAttributeTypeError(`payload.Color`, v, "string", err)
}
if err == nil {
if tmp3 != "" {
if !(tmp3 == "red" || tmp3 == "white" || tmp3 == "rose" || tmp3 == "yellow" || tmp3 == "sparkling") {
err = goa.InvalidEnumValueError(`payload.Color`, tmp3, []interface{}{"red", "white", "rose", "yellow", "sparkling"}, err)
}
}
}
target.Color = tmp3
} else {
err = goa.MissingAttributeError(`payload`, "color", err)
}
if v, ok := val["country"]; ok {
var tmp4 string
if val, ok := v.(string); ok {
tmp4 = val
} else {
err = goa.InvalidAttributeTypeError(`payload.Country`, v, "string", err)
}
if err == nil {
if len(tmp4) < 2 {
err = goa.InvalidLengthError(`payload.Country`, tmp4, len(tmp4), 2, true, err)
}
}
target.Country = tmp4
}
if v, ok := val["name"]; ok {
var tmp5 string
if val, ok := v.(string); ok {
tmp5 = val
} else {
err = goa.InvalidAttributeTypeError(`payload.Name`, v, "string", err)
}
if err == nil {
if len(tmp5) < 2 {
err = goa.InvalidLengthError(`payload.Name`, tmp5, len(tmp5), 2, true, err)
}
}
target.Name = tmp5
} else {
err = goa.MissingAttributeError(`payload`, "name", err)
}
if v, ok := val["region"]; ok {
var tmp6 string
if val, ok := v.(string); ok {
tmp6 = val
} else {
err = goa.InvalidAttributeTypeError(`payload.Region`, v, "string", err)
}
target.Region = tmp6
}
if v, ok := val["review"]; ok {
var tmp7 string
if val, ok := v.(string); ok {
tmp7 = val
} else {
err = goa.InvalidAttributeTypeError(`payload.Review`, v, "string", err)
}
if err == nil {
if len(tmp7) < 10 {
err = goa.InvalidLengthError(`payload.Review`, tmp7, len(tmp7), 10, true, err)
}
if len(tmp7) > 300 {
err = goa.InvalidLengthError(`payload.Review`, tmp7, len(tmp7), 300, false, err)
}
}
target.Review = tmp7
}
if v, ok := val["sweetness"]; ok {
var tmp8 int
if f, ok := v.(float64); ok {
tmp8 = int(f)
} else {
err = goa.InvalidAttributeTypeError(`payload.Sweetness`, v, "int", err)
}
if err == nil {
if tmp8 < 1 {
err = goa.InvalidRangeError(`payload.Sweetness`, tmp8, 1, true, err)
}
if tmp8 > 5 {
err = goa.InvalidRangeError(`payload.Sweetness`, tmp8, 5, false, err)
}
}
target.Sweetness = tmp8
}
if v, ok := val["varietal"]; ok {
var tmp9 string
if val, ok := v.(string); ok {
tmp9 = val
//.........这里部分代码省略.........