當前位置: 首頁>>代碼示例>>Golang>>正文


Golang goa.InvalidParamTypeError函數代碼示例

本文整理匯總了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
}
開發者ID:cw2018,項目名稱:goa,代碼行數:28,代碼來源:contexts.go

示例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
}
開發者ID:cw2018,項目名稱:goa,代碼行數:29,代碼來源:contexts.go

示例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
}
開發者ID:tylerb,項目名稱:goa,代碼行數:19,代碼來源:contexts.go

示例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
}
開發者ID:AidHamza,項目名稱:congo,代碼行數:23,代碼來源:contexts.go

示例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))
	})
開發者ID:harboe,項目名稱:goa,代碼行數:30,代碼來源:error_test.go


注:本文中的github.com/raphael/goa.InvalidParamTypeError函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。