本文整理汇总了Golang中github.com/raphael/goa.InvalidParamTypeError函数的典型用法代码示例。如果您正苦于以下问题:Golang InvalidParamTypeError函数的具体用法?Golang InvalidParamTypeError怎么用?Golang InvalidParamTypeError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了InvalidParamTypeError函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewUpdateBottleContext
// NewUpdateBottleContext parses the incoming request URL and body, performs validations and creates the
// context used by the bottle controller update action.
func NewUpdateBottleContext(c *goa.Context) (*UpdateBottleContext, error) {
var err error
ctx := UpdateBottleContext{Context: c}
rawAccountID, ok := c.Get("accountID")
if ok {
if accountID, err2 := strconv.Atoi(rawAccountID); err2 == nil {
ctx.AccountID = int(accountID)
} else {
err = goa.InvalidParamTypeError("accountID", rawAccountID, "integer", err)
}
}
rawBottleID, ok := c.Get("bottleID")
if ok {
if bottleID, err2 := strconv.Atoi(rawBottleID); err2 == nil {
ctx.BottleID = int(bottleID)
} else {
err = goa.InvalidParamTypeError("bottleID", rawBottleID, "integer", err)
}
}
p, err := NewUpdateBottlePayload(c.Payload())
if err != nil {
return nil, err
}
ctx.Payload = p
return &ctx, err
}
示例2: NewListBottleContext
// NewListBottleContext parses the incoming request URL and body, performs validations and creates the
// context used by the bottle controller list action.
func NewListBottleContext(c *goa.Context) (*ListBottleContext, error) {
var err error
ctx := ListBottleContext{Context: c}
rawAccountID, ok := c.Get("accountID")
if ok {
if accountID, err2 := strconv.Atoi(rawAccountID); err2 == nil {
ctx.AccountID = int(accountID)
} else {
err = goa.InvalidParamTypeError("accountID", rawAccountID, "integer", err)
}
}
rawYears, ok := c.Get("years")
if ok {
elemsYears := strings.Split(rawYears, ",")
elemsYears2 := make([]int, len(elemsYears))
for i, rawElem := range elemsYears {
if elem, err2 := strconv.Atoi(rawElem); err2 == nil {
elemsYears2[i] = int(elem)
} else {
err = goa.InvalidParamTypeError("elem", rawElem, "integer", err)
}
}
ctx.Years = elemsYears2
ctx.HasYears = true
}
return &ctx, err
}
示例3: NewShowBottleContext
// NewShowBottleContext parses the incoming request URL and body, performs validations and creates the
// context used by the bottle controller show action.
func NewShowBottleContext(c *goa.Context) (*ShowBottleContext, error) {
var err error
ctx := ShowBottleContext{Context: c}
rawAccountID := c.Get("accountID")
if accountID, err2 := strconv.Atoi(rawAccountID); err2 == nil {
ctx.AccountID = int(accountID)
} else {
err = goa.InvalidParamTypeError("accountID", rawAccountID, "integer", err)
}
rawBottleID := c.Get("bottleID")
if bottleID, err2 := strconv.Atoi(rawBottleID); err2 == nil {
ctx.BottleID = int(bottleID)
} else {
err = goa.InvalidParamTypeError("bottleID", rawBottleID, "integer", err)
}
return &ctx, err
}
示例4: NewShowUserContext
// NewShowUserContext parses the incoming request URL and body, performs validations and creates the
// context used by the user controller show action.
func NewShowUserContext(c *goa.Context) (*ShowUserContext, error) {
var err error
ctx := ShowUserContext{Context: c}
rawAccountID, ok := c.Get("accountID")
if ok {
if accountID, err2 := strconv.Atoi(rawAccountID); err2 == nil {
ctx.AccountID = int(accountID)
} else {
err = goa.InvalidParamTypeError("accountID", rawAccountID, "integer", err)
}
}
rawUserID, ok := c.Get("userID")
if ok {
if userID, err2 := strconv.Atoi(rawUserID); err2 == nil {
ctx.UserID = int(userID)
} else {
err = goa.InvalidParamTypeError("userID", rawUserID, "integer", err)
}
}
return &ctx, err
}
示例5:
Ω(badReq.Error()).Should(Equal(rawErr.Error()))
})
})
var _ = Describe("InvalidParamTypeError", func() {
var valErr, err error
name := "param"
val := 42
expected := "43"
BeforeEach(func() {
err = nil
})
JustBeforeEach(func() {
valErr = goa.InvalidParamTypeError(name, val, expected, 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.ErrInvalidParamType))))
Ω(tErr.Mesg).Should(ContainSubstring(name))
Ω(tErr.Mesg).Should(ContainSubstring("%d", val))
Ω(tErr.Mesg).Should(ContainSubstring(expected))
})