当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.Get方法代码示例

本文整理汇总了Golang中github.com/goadesign/goa.Context.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Get方法的具体用法?Golang Context.Get怎么用?Golang Context.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/goadesign/goa.Context的用法示例。


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

示例1: 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 := c.Get("accountID")
	if rawAccountID != "" {
		if accountID, err2 := strconv.Atoi(rawAccountID); err2 == nil {
			ctx.AccountID = int(accountID)
		} else {
			err = goa.InvalidParamTypeError("accountID", rawAccountID, "integer", err)
		}
	}
	rawYears := c.Get("years")
	if rawYears != "" {
		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
	}
	return &ctx, err
}
开发者ID:derekperkins,项目名称:gorma,代码行数:28,代码来源:contexts.go

示例2: NewShowAccountContext

// NewShowAccountContext parses the incoming request URL and body, performs validations and creates the
// context used by the account controller show action.
func NewShowAccountContext(c *goa.Context) (*ShowAccountContext, error) {
	var err error
	ctx := ShowAccountContext{Context: c}
	rawAccountID := c.Get("accountID")
	if rawAccountID != "" {
		if accountID, err2 := strconv.Atoi(rawAccountID); err2 == nil {
			ctx.AccountID = int(accountID)
		} else {
			err = goa.InvalidParamTypeError("accountID", rawAccountID, "integer", err)
		}
	}
	return &ctx, err
}
开发者ID:derekperkins,项目名称:gorma,代码行数:15,代码来源:contexts.go

示例3:

	Describe("ResponseStatus", func() {
		It("returns 0 if not initialized", func() {
			Ω(ctx.ResponseStatus()).Should(Equal(0))
		})
	})

	Describe("ResponseLength", func() {
		It("returns 0 if not initialized", func() {
			Ω(ctx.ResponseLength()).Should(Equal(0))
		})
	})

	Describe("Get", func() {
		It(`returns "", false if not initialized`, func() {
			p := ctx.Get("foo")
			Ω(p).Should(Equal(""))
		})
	})

	Describe("GetMany", func() {
		It("returns nil if not initialized", func() {
			Ω(ctx.GetMany("foo")).Should(BeNil())
		})
	})

	Describe("RawPayload", func() {
		It("returns nil if not initialized", func() {
			Ω(ctx.RawPayload()).Should(BeNil())
		})
	})
开发者ID:jianjunliu,项目名称:goa,代码行数:30,代码来源:context_test.go

示例4:

			var p url.Values

			BeforeEach(func() {
				var err error
				r, err = http.NewRequest("GET", "/foo", nil)
				Ω(err).ShouldNot(HaveOccurred())
				rw = new(TestResponseWriter)
				p = url.Values{"id": []string{"42"}, "sort": []string{"asc"}}
			})

			JustBeforeEach(func() {
				handleFunc(rw, r, p)
			})

			It("creates a handle that handles the request", func() {
				i := ctx.Get("id")
				Ω(i).Should(Equal("42"))
				s := ctx.Get("sort")
				Ω(s).Should(Equal("asc"))
				tw := rw.(*TestResponseWriter)
				Ω(tw.Status).Should(Equal(respStatus))
				Ω(tw.Body).Should(Equal(respContent))
			})

			Context("and middleware", func() {
				middlewareCalled := false

				BeforeEach(func() {
					s.Use(TMiddleware(&middlewareCalled))
				})
开发者ID:is00hcw,项目名称:goa,代码行数:30,代码来源:service_test.go


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