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

Golang goa.InvalidLengthError函数代码示例

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

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



在下文中一共展示了InvalidLengthError函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: 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


示例2: Dump

// Dump produces raw data from an instance of SeriesCollection running all the
// validations. See LoadSeriesCollection for the definition of raw data.
func (mt SeriesCollection) Dump(view SeriesCollectionViewEnum) ([]map[string]interface{}, error) {
	var err error
	var res []map[string]interface{}
	if view == SeriesCollectionDefaultView {
		res = make([]map[string]interface{}, len(mt))
		for i, tmp48 := range mt {
			if len(tmp48.Name) < 2 {
				err = goa.InvalidLengthError(`default view[*].name`, tmp48.Name, 2, true, err)
			}
			tmp50 := map[string]interface{}{
				"href": tmp48.Href,
				"id":   tmp48.ID,
				"name": tmp48.Name,
			}
			res[i] = tmp50
			if err == nil {
				links := make(map[string]interface{})
				tmp49 := map[string]interface{}{
					"href": tmp48.Account.Href,
					"id":   tmp48.Account.ID,
					"name": tmp48.Account.Name,
				}
				links["account"] = tmp49
				res[i]["links"] = links
			}
		}
	}
	if view == SeriesCollectionTinyView {
		res = make([]map[string]interface{}, len(mt))
		for i, tmp51 := range mt {
			if len(tmp51.Name) < 2 {
				err = goa.InvalidLengthError(`tiny view[*].name`, tmp51.Name, 2, true, err)
			}
			tmp53 := map[string]interface{}{
				"href": tmp51.Href,
				"id":   tmp51.ID,
				"name": tmp51.Name,
			}
			res[i] = tmp53
			if err == nil {
				links := make(map[string]interface{})
				tmp52 := map[string]interface{}{
					"href": tmp51.Account.Href,
					"id":   tmp51.Account.ID,
					"name": tmp51.Account.Name,
				}
				links["account"] = tmp52
				res[i]["links"] = links
			}
		}
	}
	return res, err
}
开发者ID:AidHamza,项目名称:congo,代码行数:55,代码来源:media_types.go


示例3: NewUpdateUserPayload

// NewUpdateUserPayload instantiates a UpdateUserPayload from a raw request body.
// It validates each field and returns an error if any validation fails.
func NewUpdateUserPayload(raw interface{}) (*UpdateUserPayload, error) {
	var err error
	var p *UpdateUserPayload
	if val, ok := raw.(map[string]interface{}); ok {
		p = new(UpdateUserPayload)
		if v, ok := val["email"]; ok {
			var tmp8 string
			if val, ok := v.(string); ok {
				tmp8 = val
			} else {
				err = goa.InvalidAttributeTypeError(`payload.Email`, v, "string", err)
			}
			if err == nil {
				if len(tmp8) < 2 {
					err = goa.InvalidLengthError(`payload.Email`, tmp8, 2, true, err)
				}
			}
			p.Email = tmp8
		}
		if v, ok := val["first_name"]; ok {
			var tmp9 string
			if val, ok := v.(string); ok {
				tmp9 = val
			} else {
				err = goa.InvalidAttributeTypeError(`payload.FirstName`, v, "string", err)
			}
			if err == nil {
				if len(tmp9) < 2 {
					err = goa.InvalidLengthError(`payload.FirstName`, tmp9, 2, true, err)
				}
			}
			p.FirstName = tmp9
		}
		if v, ok := val["last_name"]; ok {
			var tmp10 string
			if val, ok := v.(string); ok {
				tmp10 = val
			} else {
				err = goa.InvalidAttributeTypeError(`payload.LastName`, v, "string", err)
			}
			if err == nil {
				if len(tmp10) < 2 {
					err = goa.InvalidLengthError(`payload.LastName`, tmp10, 2, true, err)
				}
			}
			p.LastName = tmp10
		}
	} else {
		err = goa.InvalidAttributeTypeError(`payload`, raw, "map[string]interface{}", err)
	}
	return p, err
}
开发者ID:AidHamza,项目名称:congo,代码行数:54,代码来源:contexts.go


示例4: Validate

// Validate validates the media type instance.
func (mt *Series) Validate() (err error) {
	if mt.Account.CreatedAt != "" {
		if err2 := goa.ValidateFormat(goa.FormatDateTime, mt.Account.CreatedAt); err2 != nil {
			err = goa.InvalidFormatError(`response.account.created_at`, mt.Account.CreatedAt, goa.FormatDateTime, err2, err)
		}
	}
	if mt.Account.CreatedBy != "" {
		if err2 := goa.ValidateFormat(goa.FormatEmail, mt.Account.CreatedBy); err2 != nil {
			err = goa.InvalidFormatError(`response.account.created_by`, mt.Account.CreatedBy, goa.FormatEmail, err2, err)
		}
	}
	if mt.CreatedAt != "" {
		if err2 := goa.ValidateFormat(goa.FormatDateTime, mt.CreatedAt); err2 != nil {
			err = goa.InvalidFormatError(`response.created_at`, mt.CreatedAt, goa.FormatDateTime, err2, err)
		}
	}
	if len(mt.Name) < 2 {
		err = goa.InvalidLengthError(`response.name`, mt.Name, 2, true, err)
	}
	if mt.UpdatedAt != "" {
		if err2 := goa.ValidateFormat(goa.FormatDateTime, mt.UpdatedAt); err2 != nil {
			err = goa.InvalidFormatError(`response.updated_at`, mt.UpdatedAt, goa.FormatDateTime, err2, err)
		}
	}
	return
}
开发者ID:AidHamza,项目名称:congo,代码行数:27,代码来源:media_types.go


示例5: MarshalBottleTiny

// MarshalBottleTiny validates and renders an instance of Bottle into a interface{}
// using view "tiny".
func MarshalBottleTiny(source *Bottle, inErr error) (target map[string]interface{}, err error) {
	err = inErr
	if len(source.Name) < 2 {
		err = goa.InvalidLengthError(`.name`, source.Name, len(source.Name), 2, true, err)
	}
	if source.Rating < 1 {
		err = goa.InvalidRangeError(`.rating`, source.Rating, 1, true, err)
	}
	if source.Rating > 5 {
		err = goa.InvalidRangeError(`.rating`, source.Rating, 5, false, err)
	}
	tmp31 := map[string]interface{}{
		"href":   source.Href,
		"id":     source.ID,
		"name":   source.Name,
		"rating": source.Rating,
	}
	target = tmp31
	if err == nil {
		links := make(map[string]interface{})
		links["account"], err = MarshalAccountLink(source.Account, err)
		target["links"] = links
	}
	return
}
开发者ID:tylerb,项目名称:goa,代码行数:27,代码来源:media_types.go


示例6: 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


示例7: MarshalBottle

// MarshalBottle validates and renders an instance of Bottle into a interface{}
// using view "default".
func MarshalBottle(source *Bottle, inErr error) (target map[string]interface{}, err error) {
	err = inErr
	if len(source.Name) < 2 {
		err = goa.InvalidLengthError(`.name`, source.Name, len(source.Name), 2, true, err)
	}
	if source.Rating < 1 {
		err = goa.InvalidRangeError(`.rating`, source.Rating, 1, true, err)
	}
	if source.Rating > 5 {
		err = goa.InvalidRangeError(`.rating`, source.Rating, 5, false, err)
	}
	if len(source.Varietal) < 4 {
		err = goa.InvalidLengthError(`.varietal`, source.Varietal, len(source.Varietal), 4, true, err)
	}
	if len(source.Vineyard) < 2 {
		err = goa.InvalidLengthError(`.vineyard`, source.Vineyard, len(source.Vineyard), 2, true, err)
	}
	if source.Vintage < 1900 {
		err = goa.InvalidRangeError(`.vintage`, source.Vintage, 1900, true, err)
	}
	if source.Vintage > 2020 {
		err = goa.InvalidRangeError(`.vintage`, source.Vintage, 2020, false, err)
	}
	tmp29 := map[string]interface{}{
		"href":     source.Href,
		"id":       source.ID,
		"name":     source.Name,
		"rating":   source.Rating,
		"varietal": source.Varietal,
		"vineyard": source.Vineyard,
		"vintage":  source.Vintage,
	}
	target = tmp29
	if err == nil {
		links := make(map[string]interface{})
		links["account"], err = MarshalAccountLink(source.Account, err)
		target["links"] = links
	}
	return
}
开发者ID:tylerb,项目名称:goa,代码行数:42,代码来源:media_types.go


示例8: MarshalBottlePayload

// MarshalBottlePayload validates and renders an instance of BottlePayload into a interface{}
func MarshalBottlePayload(source *BottlePayload, inErr error) (target map[string]interface{}, err error) {
	err = inErr
	if source.Color != "" {
		if !(source.Color == "red" || source.Color == "white" || source.Color == "rose" || source.Color == "yellow" || source.Color == "sparkling") {
			err = goa.InvalidEnumValueError(`.color`, source.Color, []interface{}{"red", "white", "rose", "yellow", "sparkling"}, err)
		}
	}
	if len(source.Country) < 2 {
		err = goa.InvalidLengthError(`.country`, source.Country, len(source.Country), 2, true, err)
	}
	if len(source.Name) < 2 {
		err = goa.InvalidLengthError(`.name`, source.Name, len(source.Name), 2, true, err)
	}
	if len(source.Review) < 10 {
		err = goa.InvalidLengthError(`.review`, source.Review, len(source.Review), 10, true, err)
	}
	if len(source.Review) > 300 {
		err = goa.InvalidLengthError(`.review`, source.Review, len(source.Review), 300, false, err)
	}
	if source.Sweetness < 1 {
		err = goa.InvalidRangeError(`.sweetness`, source.Sweetness, 1, true, err)
	}
	if source.Sweetness > 5 {
		err = goa.InvalidRangeError(`.sweetness`, source.Sweetness, 5, false, err)
	}
	if len(source.Varietal) < 4 {
		err = goa.InvalidLengthError(`.varietal`, source.Varietal, len(source.Varietal), 4, true, err)
	}
	if len(source.Vineyard) < 2 {
		err = goa.InvalidLengthError(`.vineyard`, source.Vineyard, len(source.Vineyard), 2, true, err)
	}
	if source.Vintage < 1900 {
		err = goa.InvalidRangeError(`.vintage`, source.Vintage, 1900, true, err)
	}
	if source.Vintage > 2020 {
		err = goa.InvalidRangeError(`.vintage`, source.Vintage, 2020, false, err)
	}
	tmp52 := map[string]interface{}{
		"color":     source.Color,
		"country":   source.Country,
		"name":      source.Name,
		"region":    source.Region,
		"review":    source.Review,
		"sweetness": source.Sweetness,
		"varietal":  source.Varietal,
		"vineyard":  source.Vineyard,
		"vintage":   source.Vintage,
	}
	target = tmp52
	return
}
开发者ID:tylerb,项目名称:goa,代码行数:52,代码来源:user_types.go


示例9: Validate

// Validate validates the type instance.
func (ut *BottlePayload) Validate() (err error) {
	if ut.Color != "" {
		if !(ut.Color == "red" || ut.Color == "white" || ut.Color == "rose" || ut.Color == "yellow" || ut.Color == "sparkling") {
			err = goa.InvalidEnumValueError(`response.color`, ut.Color, []interface{}{"red", "white", "rose", "yellow", "sparkling"}, err)
		}
	}
	if len(ut.Country) < 2 {
		err = goa.InvalidLengthError(`response.country`, ut.Country, len(ut.Country), 2, true, err)
	}
	if len(ut.Name) < 2 {
		err = goa.InvalidLengthError(`response.name`, ut.Name, len(ut.Name), 2, true, err)
	}
	if len(ut.Review) < 10 {
		err = goa.InvalidLengthError(`response.review`, ut.Review, len(ut.Review), 10, true, err)
	}
	if len(ut.Review) > 300 {
		err = goa.InvalidLengthError(`response.review`, ut.Review, len(ut.Review), 300, false, err)
	}
	if ut.Sweetness < 1 {
		err = goa.InvalidRangeError(`response.sweetness`, ut.Sweetness, 1, true, err)
	}
	if ut.Sweetness > 5 {
		err = goa.InvalidRangeError(`response.sweetness`, ut.Sweetness, 5, false, err)
	}
	if len(ut.Varietal) < 4 {
		err = goa.InvalidLengthError(`response.varietal`, ut.Varietal, len(ut.Varietal), 4, true, err)
	}
	if len(ut.Vineyard) < 2 {
		err = goa.InvalidLengthError(`response.vineyard`, ut.Vineyard, len(ut.Vineyard), 2, true, err)
	}
	if ut.Vintage < 1900 {
		err = goa.InvalidRangeError(`response.vintage`, ut.Vintage, 1900, true, err)
	}
	if ut.Vintage > 2020 {
		err = goa.InvalidRangeError(`response.vintage`, ut.Vintage, 2020, false, err)
	}
	return
}
开发者ID:tylerb,项目名称:goa,代码行数:39,代码来源:user_types.go


示例10: Validate

// Validate validates the media type instance.
func (mt BottleCollection) Validate() (err error) {
	for _, e := range mt {
		if e.Account.CreatedAt != "" {
			if err2 := goa.ValidateFormat(goa.FormatDateTime, e.Account.CreatedAt); err2 != nil {
				err = goa.InvalidFormatError(`response[*].account.created_at`, e.Account.CreatedAt, goa.FormatDateTime, err2, err)
			}
		}
		if e.Account.CreatedBy != "" {
			if err2 := goa.ValidateFormat(goa.FormatEmail, e.Account.CreatedBy); err2 != nil {
				err = goa.InvalidFormatError(`response[*].account.created_by`, e.Account.CreatedBy, goa.FormatEmail, err2, err)
			}
		}
		if e.Color != "" {
			if !(e.Color == "red" || e.Color == "white" || e.Color == "rose" || e.Color == "yellow" || e.Color == "sparkling") {
				err = goa.InvalidEnumValueError(`response[*].color`, e.Color, []interface{}{"red", "white", "rose", "yellow", "sparkling"}, err)
			}
		}
		if len(e.Country) < 2 {
			err = goa.InvalidLengthError(`response[*].country`, e.Country, len(e.Country), 2, true, err)
		}
		if e.CreatedAt != "" {
			if err2 := goa.ValidateFormat(goa.FormatDateTime, e.CreatedAt); err2 != nil {
				err = goa.InvalidFormatError(`response[*].created_at`, e.CreatedAt, goa.FormatDateTime, err2, err)
			}
		}
		if len(e.Name) < 2 {
			err = goa.InvalidLengthError(`response[*].name`, e.Name, len(e.Name), 2, true, err)
		}
		if e.Rating < 1 {
			err = goa.InvalidRangeError(`response[*].rating`, e.Rating, 1, true, err)
		}
		if e.Rating > 5 {
			err = goa.InvalidRangeError(`response[*].rating`, e.Rating, 5, false, err)
		}
		if len(e.Review) < 10 {
			err = goa.InvalidLengthError(`response[*].review`, e.Review, len(e.Review), 10, true, err)
		}
		if len(e.Review) > 300 {
			err = goa.InvalidLengthError(`response[*].review`, e.Review, len(e.Review), 300, false, err)
		}
		if e.Sweetness < 1 {
			err = goa.InvalidRangeError(`response[*].sweetness`, e.Sweetness, 1, true, err)
		}
		if e.Sweetness > 5 {
			err = goa.InvalidRangeError(`response[*].sweetness`, e.Sweetness, 5, false, err)
		}
		if e.UpdatedAt != "" {
			if err2 := goa.ValidateFormat(goa.FormatDateTime, e.UpdatedAt); err2 != nil {
				err = goa.InvalidFormatError(`response[*].updated_at`, e.UpdatedAt, goa.FormatDateTime, err2, err)
			}
		}
		if len(e.Varietal) < 4 {
			err = goa.InvalidLengthError(`response[*].varietal`, e.Varietal, len(e.Varietal), 4, true, err)
		}
		if len(e.Vineyard) < 2 {
			err = goa.InvalidLengthError(`response[*].vineyard`, e.Vineyard, len(e.Vineyard), 2, true, err)
		}
		if e.Vintage < 1900 {
			err = goa.InvalidRangeError(`response[*].vintage`, e.Vintage, 1900, true, err)
		}
		if e.Vintage > 2020 {
			err = goa.InvalidRangeError(`response[*].vintage`, e.Vintage, 2020, false, err)
		}
	}
	return
}
开发者ID:tylerb,项目名称:goa,代码行数:67,代码来源:media_types.go


示例11: LoadSeriesCollection


//.........这里部分代码省略.........
							}
							tmp37.Href = tmp40
						}
						if v, ok := val["id"]; ok {
							var tmp41 int
							if f, ok := v.(float64); ok {
								tmp41 = int(f)
							} else {
								err = goa.InvalidAttributeTypeError(`[*].Account.ID`, v, "int", err)
							}
							tmp37.ID = tmp41
						}
						if v, ok := val["name"]; ok {
							var tmp42 string
							if val, ok := v.(string); ok {
								tmp42 = val
							} else {
								err = goa.InvalidAttributeTypeError(`[*].Account.Name`, v, "string", err)
							}
							tmp37.Name = tmp42
						}
					} else {
						err = goa.InvalidAttributeTypeError(`[*].Account`, v, "map[string]interface{}", err)
					}
					tmp36.Account = tmp37
				}
				if v, ok := val["created_at"]; ok {
					var tmp43 string
					if val, ok := v.(string); ok {
						tmp43 = val
					} else {
						err = goa.InvalidAttributeTypeError(`[*].CreatedAt`, v, "string", err)
					}
					if err == nil {
						if tmp43 != "" {
							if err2 := goa.ValidateFormat(goa.FormatDateTime, tmp43); err2 != nil {
								err = goa.InvalidFormatError(`[*].CreatedAt`, tmp43, goa.FormatDateTime, err2, err)
							}
						}
					}
					tmp36.CreatedAt = tmp43
				}
				if v, ok := val["href"]; ok {
					var tmp44 string
					if val, ok := v.(string); ok {
						tmp44 = val
					} else {
						err = goa.InvalidAttributeTypeError(`[*].Href`, v, "string", err)
					}
					tmp36.Href = tmp44
				}
				if v, ok := val["id"]; ok {
					var tmp45 int
					if f, ok := v.(float64); ok {
						tmp45 = int(f)
					} else {
						err = goa.InvalidAttributeTypeError(`[*].ID`, v, "int", err)
					}
					tmp36.ID = tmp45
				}
				if v, ok := val["name"]; ok {
					var tmp46 string
					if val, ok := v.(string); ok {
						tmp46 = val
					} else {
						err = goa.InvalidAttributeTypeError(`[*].Name`, v, "string", err)
					}
					if err == nil {
						if len(tmp46) < 2 {
							err = goa.InvalidLengthError(`[*].Name`, tmp46, 2, true, err)
						}
					}
					tmp36.Name = tmp46
				}
				if v, ok := val["updated_at"]; ok {
					var tmp47 string
					if val, ok := v.(string); ok {
						tmp47 = val
					} else {
						err = goa.InvalidAttributeTypeError(`[*].UpdatedAt`, v, "string", err)
					}
					if err == nil {
						if tmp47 != "" {
							if err2 := goa.ValidateFormat(goa.FormatDateTime, tmp47); err2 != nil {
								err = goa.InvalidFormatError(`[*].UpdatedAt`, tmp47, goa.FormatDateTime, err2, err)
							}
						}
					}
					tmp36.UpdatedAt = tmp47
				}
			} else {
				err = goa.InvalidAttributeTypeError(`[*]`, v, "map[string]interface{}", err)
			}
			res[i] = tmp36
		}
	} else {
		err = goa.InvalidAttributeTypeError(``, raw, "[]interface{}", err)
	}
	return res, err
}
开发者ID:AidHamza,项目名称:congo,代码行数:101,代码来源:media_types.go


示例12: MarshalBottleFull

// MarshalBottleFull validates and renders an instance of Bottle into a interface{}
// using view "full".
func MarshalBottleFull(source *Bottle, inErr error) (target map[string]interface{}, err error) {
	err = inErr
	if source.Color != "" {
		if !(source.Color == "red" || source.Color == "white" || source.Color == "rose" || source.Color == "yellow" || source.Color == "sparkling") {
			err = goa.InvalidEnumValueError(`.color`, source.Color, []interface{}{"red", "white", "rose", "yellow", "sparkling"}, err)
		}
	}
	if len(source.Country) < 2 {
		err = goa.InvalidLengthError(`.country`, source.Country, len(source.Country), 2, true, err)
	}
	if source.CreatedAt != "" {
		if err2 := goa.ValidateFormat(goa.FormatDateTime, source.CreatedAt); err2 != nil {
			err = goa.InvalidFormatError(`.created_at`, source.CreatedAt, goa.FormatDateTime, err2, err)
		}
	}
	if len(source.Name) < 2 {
		err = goa.InvalidLengthError(`.name`, source.Name, len(source.Name), 2, true, err)
	}
	if source.Rating < 1 {
		err = goa.InvalidRangeError(`.rating`, source.Rating, 1, true, err)
	}
	if source.Rating > 5 {
		err = goa.InvalidRangeError(`.rating`, source.Rating, 5, false, err)
	}
	if len(source.Review) < 10 {
		err = goa.InvalidLengthError(`.review`, source.Review, len(source.Review), 10, true, err)
	}
	if len(source.Review) > 300 {
		err = goa.InvalidLengthError(`.review`, source.Review, len(source.Review), 300, false, err)
	}
	if source.Sweetness < 1 {
		err = goa.InvalidRangeError(`.sweetness`, source.Sweetness, 1, true, err)
	}
	if source.Sweetness > 5 {
		err = goa.InvalidRangeError(`.sweetness`, source.Sweetness, 5, false, err)
	}
	if source.UpdatedAt != "" {
		if err2 := goa.ValidateFormat(goa.FormatDateTime, source.UpdatedAt); err2 != nil {
			err = goa.InvalidFormatError(`.updated_at`, source.UpdatedAt, goa.FormatDateTime, err2, err)
		}
	}
	if len(source.Varietal) < 4 {
		err = goa.InvalidLengthError(`.varietal`, source.Varietal, len(source.Varietal), 4, true, err)
	}
	if len(source.Vineyard) < 2 {
		err = goa.InvalidLengthError(`.vineyard`, source.Vineyard, len(source.Vineyard), 2, true, err)
	}
	if source.Vintage < 1900 {
		err = goa.InvalidRangeError(`.vintage`, source.Vintage, 1900, true, err)
	}
	if source.Vintage > 2020 {
		err = goa.InvalidRangeError(`.vintage`, source.Vintage, 2020, false, err)
	}
	tmp30 := map[string]interface{}{
		"color":      source.Color,
		"country":    source.Country,
		"created_at": source.CreatedAt,
		"href":       source.Href,
		"id":         source.ID,
		"name":       source.Name,
		"rating":     source.Rating,
		"region":     source.Region,
		"review":     source.Review,
		"sweetness":  source.Sweetness,
		"updated_at": source.UpdatedAt,
		"varietal":   source.Varietal,
		"vineyard":   source.Vineyard,
		"vintage":    source.Vintage,
	}
	if source.Account != nil {
		tmp30["account"], err = MarshalAccount(source.Account, err)
	}
	target = tmp30
	if err == nil {
		links := make(map[string]interface{})
		links["account"], err = MarshalAccountLink(source.Account, err)
		target["links"] = links
	}
	return
}
开发者ID:tylerb,项目名称:goa,代码行数:82,代码来源:media_types.go


示例13: UnmarshalBottle

// UnmarshalBottle unmarshals and validates a raw interface{} into an instance of Bottle
func UnmarshalBottle(source interface{}, inErr error) (target *Bottle, err error) {
	err = inErr
	if val, ok := source.(map[string]interface{}); ok {
		target = new(Bottle)
		if v, ok := val["account"]; ok {
			var tmp32 *Account
			tmp32, err = UnmarshalAccount(v, err)
			target.Account = tmp32
		}
		if v, ok := val["color"]; ok {
			var tmp33 string
			if val, ok := v.(string); ok {
				tmp33 = val
			} else {
				err = goa.InvalidAttributeTypeError(`load.Color`, v, "string", err)
			}
			if err == nil {
				if tmp33 != "" {
					if !(tmp33 == "red" || tmp33 == "white" || tmp33 == "rose" || tmp33 == "yellow" || tmp33 == "sparkling") {
						err = goa.InvalidEnumValueError(`load.Color`, tmp33, []interface{}{"red", "white", "rose", "yellow", "sparkling"}, err)
					}
				}
			}
			target.Color = tmp33
		}
		if v, ok := val["country"]; ok {
			var tmp34 string
			if val, ok := v.(string); ok {
				tmp34 = val
			} else {
				err = goa.InvalidAttributeTypeError(`load.Country`, v, "string", err)
			}
			if err == nil {
				if len(tmp34) < 2 {
					err = goa.InvalidLengthError(`load.Country`, tmp34, len(tmp34), 2, true, err)
				}
			}
			target.Country = tmp34
		}
		if v, ok := val["created_at"]; ok {
			var tmp35 string
			if val, ok := v.(string); ok {
				tmp35 = val
			} else {
				err = goa.InvalidAttributeTypeError(`load.CreatedAt`, v, "string", err)
			}
			if err == nil {
				if tmp35 != "" {
					if err2 := goa.ValidateFormat(goa.FormatDateTime, tmp35); err2 != nil {
						err = goa.InvalidFormatError(`load.CreatedAt`, tmp35, goa.FormatDateTime, err2, err)
					}
				}
			}
			target.CreatedAt = tmp35
		}
		if v, ok := val["href"]; ok {
			var tmp36 string
			if val, ok := v.(string); ok {
				tmp36 = val
			} else {
				err = goa.InvalidAttributeTypeError(`load.Href`, v, "string", err)
			}
			target.Href = tmp36
		}
		if v, ok := val["id"]; ok {
			var tmp37 int
			if f, ok := v.(float64); ok {
				tmp37 = int(f)
			} else {
				err = goa.InvalidAttributeTypeError(`load.ID`, v, "int", err)
			}
			target.ID = tmp37
		}
		if v, ok := val["name"]; ok {
			var tmp38 string
			if val, ok := v.(string); ok {
				tmp38 = val
			} else {
				err = goa.InvalidAttributeTypeError(`load.Name`, v, "string", err)
			}
			if err == nil {
				if len(tmp38) < 2 {
					err = goa.InvalidLengthError(`load.Name`, tmp38, len(tmp38), 2, true, err)
				}
			}
			target.Name = tmp38
		}
		if v, ok := val["rating"]; ok {
			var tmp39 int
			if f, ok := v.(float64); ok {
				tmp39 = int(f)
			} else {
				err = goa.InvalidAttributeTypeError(`load.Rating`, v, "int", err)
			}
			if err == nil {
				if tmp39 < 1 {
					err = goa.InvalidRangeError(`load.Rating`, tmp39, 1, true, err)
				}
				if tmp39 > 5 {
//.........这里部分代码省略.........
开发者ID:tylerb,项目名称:goa,代码行数:101,代码来源:media_types.go


示例14:

	})
})

var _ = Describe("InvalidLengthError", func() {
	var valErr, err error
	ctx := "ctx"
	target := "target"
	value := 42
	min := true

	BeforeEach(func() {
		err = nil
	})

	JustBeforeEach(func() {
		valErr = goa.InvalidLengthError(ctx, target, value, min, 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.ErrInvalidLength))))
		Ω(tErr.Mesg).Should(ContainSubstring(ctx))
		Ω(tErr.Mesg).Should(ContainSubstring("greater or equal"))
		Ω(tErr.Mesg).Should(ContainSubstring(fmt.Sprintf("%#v", value)))
		Ω(tErr.Mesg).Should(ContainSubstring(target))
	})
开发者ID:harboe,项目名称:goa,代码行数:31,代码来源:error_test.go


示例15: Validate

// Validate validates the media type instance.
func (mt *Bottle) Validate() (err error) {
	if mt.Account.CreatedAt != "" {
		if err2 := goa.ValidateFormat(goa.FormatDateTime, mt.Account.CreatedAt); err2 != nil {
			err = goa.InvalidFormatError(`response.account.created_at`, mt.Account.CreatedAt, goa.FormatDateTime, err2, err)
		}
	}
	if mt.Account.CreatedBy != "" {
		if err2 := goa.ValidateFormat(goa.FormatEmail, mt.Account.CreatedBy); err2 != nil {
			err = goa.InvalidFormatError(`response.account.created_by`, mt.Account.CreatedBy, goa.FormatEmail, err2, err)
		}
	}
	if mt.Color != "" {
		if !(mt.Color == "red" || mt.Color == "white" || mt.Color == "rose" || mt.Color == "yellow" || mt.Color == "sparkling") {
			err = goa.InvalidEnumValueError(`response.color`, mt.Color, []interface{}{"red", "white", "rose", "yellow", "sparkling"}, err)
		}
	}
	if len(mt.Country) < 2 {
		err = goa.InvalidLengthError(`response.country`, mt.Country, 2, true, err)
	}
	if mt.CreatedAt != "" {
		if err2 := goa.ValidateFormat(goa.FormatDateTime, mt.CreatedAt); err2 != nil {
			err = goa.InvalidFormatError(`response.created_at`, mt.CreatedAt, goa.FormatDateTime, err2, err)
		}
	}
	if len(mt.Name) < 2 {
		err = goa.InvalidLengthError(`response.name`, mt.Name, 2, true, err)
	}
	if mt.Rating < 1 {
		err = goa.InvalidRangeError(`response.rating`, mt.Rating, 1, true, err)
	}
	if mt.Rating > 5 {
		err = goa.InvalidRangeError(`response.rating`, mt.Rating, 5, false, err)
	}
	if len(mt.Review) < 10 {
		err = goa.InvalidLengthError(`response.review`, mt.Review, 10, true, err)
	}
	if len(mt.Review) > 300 {
		err = goa.InvalidLengthError(`response.review`, mt.Review, 300, false, err)
	}
	if mt.Sweetness < 1 {
		err = goa.InvalidRangeError(`response.sweetness`, mt.Sweetness, 1, true, err)
	}
	if mt.Sweetness > 5 {
		err = goa.InvalidRangeError(`response.sweetness`, mt.Sweetness, 5, false, err)
	}
	if mt.UpdatedAt != "" {
		if err2 := goa.ValidateFormat(goa.FormatDateTime, mt.UpdatedAt); err2 != nil {
			err = goa.InvalidFormatError(`response.updated_at`, mt.UpdatedAt, goa.FormatDateTime, err2, err)
		}
	}
	if len(mt.Varietal) < 4 {
		err = goa.InvalidLengthError(`response.varietal`, mt.Varietal, 4, true, err)
	}
	if len(mt.Vineyard) < 2 {
		err = goa.InvalidLengthError(`response.vineyard`, mt.Vineyard, 2, true, err)
	}
	if mt.Vintage < 1900 {
		err = goa.InvalidRangeError(`response.vintage`, mt.Vintage, 1900, true, err)
	}
	if mt.Vintage > 2020 {
		err = goa.InvalidRangeError(`response.vintage`, mt.Vintage, 2020, false, err)
	}
	return
}
开发者ID:harboe,项目名称:goa,代码行数:65,代码来源:media_types.go


示例16: LoadBottle


//.........这里部分代码省略.........
					}
					tmp29.Name = tmp34
				}
			} else {
				err = goa.InvalidAttributeTypeError(`.Account`, v, "map[string]interface{}", err)
			}
			res.Account = tmp29
		}
		if v, ok := val["color"]; ok {
			var tmp35 string
			if val, ok := v.(string); ok {
				tmp35 = val
			} else {
				err = goa.InvalidAttributeTypeError(`.Color`, v, "string", err)
			}
			if err == nil {
				if tmp35 != "" {
					if !(tmp35 == "red" || tmp35 == "white" || tmp35 == "rose" || tmp35 == "yellow" || tmp35 == "sparkling") {
						err = goa.InvalidEnumValueError(`.Color`, tmp35, []interface{}{"red", "white", "rose", "yellow", "sparkling"}, err)
					}
				}
			}
			res.Color = tmp35
		}
		if v, ok := val["country"]; ok {
			var tmp36 string
			if val, ok := v.(string); ok {
				tmp36 = val
			} else {
				err = goa.InvalidAttributeTypeError(`.Country`, v, "string", err)
			}
			if err == nil {
				if len(tmp36) < 2 {
					err = goa.InvalidLengthError(`.Country`, tmp36, 2, true, err)
				}
			}
			res.Country = tmp36
		}
		if v, ok := val["created_at"]; ok {
			var tmp37 string
			if val, ok := v.(string); ok {
				tmp37 = val
			} else {
				err = goa.InvalidAttributeTypeError(`.CreatedAt`, v, "string", err)
			}
			if err == nil {
				if tmp37 != "" {
					if err2 := goa.ValidateFormat(goa.FormatDateTime, tmp37); err2 != nil {
						err = goa.InvalidFormatError(`.CreatedAt`, tmp37, goa.FormatDateTime, err2, err)
					}
				}
			}
			res.CreatedAt = tmp37
		}
		if v, ok := val["href"]; ok {
			var tmp38 string
			if val, ok := v.(string); ok {
				tmp38 = val
			} else {
				err = goa.InvalidAttributeTypeError(`.Href`, v, "string", err)
			}
			res.Href = tmp38
		}
		if v, ok := val["id"]; ok {
			var tmp39 int
			if f, ok := v.(float64); ok {
开发者ID:harboe,项目名称:goa,代码行数:67,代码来源:media_types.go


示例17: Dump

// Dump produces raw data from an instance of BottleCollection running all the
// validations. See LoadBottleCollection for the definition of raw data.
func (mt BottleCollection) Dump(view BottleCollectionViewEnum) ([]map[string]interface{}, error) {
	var err error
	var res []map[string]interface{}
	if view == BottleCollectionDefaultView {
		res = make([]map[string]interface{}, len(mt))
		for i, tmp77 := range mt {
			if len(tmp77.Name) < 2 {
				err = goa.InvalidLengthError(`default view[*].name`, tmp77.Name, 2, true, err)
			}
			if tmp77.Rating < 1 {
				err = goa.InvalidRangeError(`default view[*].rating`, tmp77.Rating, 1, true, err)
			}
			if tmp77.Rating > 5 {
				err = goa.InvalidRangeError(`default view[*].rating`, tmp77.Rating, 5, false, err)
			}
			if len(tmp77.Varietal) < 4 {
				err = goa.InvalidLengthError(`default view[*].varietal`, tmp77.Varietal, 4, true, err)
			}
			if len(tmp77.Vineyard) < 2 {
				err = goa.InvalidLengthError(`default view[*].vineyard`, tmp77.Vineyard, 2, true, err)
			}
			if tmp77.Vintage < 1900 {
				err = goa.InvalidRangeError(`default view[*].vintage`, tmp77.Vintage, 1900, true, err)
			}
			if tmp77.Vintage > 2020 {
				err = goa.InvalidRangeError(`default view[*].vintage`, tmp77.Vintage, 2020, false, err)
			}
			tmp79 := map[string]interface{}{
				"href":     tmp77.Href,
				"id":       tmp77.ID,
				"name":     tmp77.Name,
				"rating":   tmp77.Rating,
				"varietal": tmp77.Varietal,
				"vineyard": tmp77.Vineyard,
				"vintage":  tmp77.Vintage,
			}
			res[i] = tmp79
			if err == nil {
				links := make(map[string]interface{})
				tmp78 := map[string]interface{}{
					"href": tmp77.Account.Href,
					"id":   tmp77.Account.ID,
					"name": tmp77.Account.Name,
				}
				links["account"] = tmp78
				res[i]["links"] = links
			}
		}
	}
	if view == BottleCollectionTinyView {
		res = make([]map[string]interface{}, len(mt))
		for i, tmp80 := range mt {
			if len(tmp80.Name) < 2 {
				err = goa.InvalidLengthError(`tiny view[*].name`, tmp80.Name, 2, true, err)
			}
			if tmp80.Rating < 1 {
				err = goa.InvalidRangeError(`tiny view[*].rating`, tmp80.Rating, 1, true, err)
			}
			if tmp80.Rating > 5 {
				err = goa.InvalidRangeError(`tiny view[*].rating`, tmp80.Rating, 5, false, err)
			}
			tmp82 := map[string]interface{}{
				"href":   tmp80.Href,
				"id":     tmp80.ID,
				"name":   tmp80.Name,
				"rating": tmp80.Rating,
			}
			res[i] = tmp82
			if err == nil {
				links := make(map[string]interface{})
				tmp81 := map[string]interface{}{
					"href": tmp80.Account.Href,
					"id":   tmp80.Account.ID,
					"name": tmp80.Account.Name,
				}
				links["account"] = tmp81
				res[i]["links"] = links
			}
		}
	}
	return res, err
}
开发者ID:harboe,项目名称:goa,代码行数:84,代码来源:media_types.go


示例18: 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


示例19: UnmarshalUpdateBottlePayload

// UnmarshalUpdateBottlePayload unmarshals and validates a raw interface{} into an instance of UpdateBottlePayload
func UnmarshalUpdateBottlePayload(source interface{}, inErr error) (target *UpdateBottlePayload, err error) {
	err = inErr
	if val, ok := source.(map[string]interface{}); ok {
		target = new(UpdateBottlePayload)
		if v, ok := val["color"]; ok {
			v 

鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang goa.InvalidParamTypeError函数代码示例发布时间:2022-05-28
下一篇:
Golang goa.InvalidFormatError函数代码示例发布时间: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