• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang goa.MissingAttributeError函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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
}
开发者ID:harboe,项目名称:goa,代码行数:31,代码来源:contexts.go


示例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
}
开发者ID:cw2018,项目名称:goa,代码行数:29,代码来源:contexts.go


示例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
}
开发者ID:AidHamza,项目名称:congo,代码行数:28,代码来源:contexts.go


示例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
}
开发者ID:AidHamza,项目名称:congo,代码行数:56,代码来源:contexts.go


示例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
}
开发者ID:cw2018,项目名称:goa,代码行数:21,代码来源:contexts.go


示例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
}
开发者ID:harboe,项目名称:goa,代码行数:23,代码来源:contexts.go


示例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() {
开发者ID:harboe,项目名称:goa,代码行数:31,代码来源:error_test.go


示例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
//.........这里部分代码省略.........
开发者ID:cw2018,项目名称:goa,代码行数:101,代码来源:contexts.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang goa.ValidateFormat函数代码示例发布时间:2022-05-28
下一篇:
Golang goa.InvalidRangeError函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap