本文整理匯總了Golang中github.com/raphael/goa.Context.Get方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Get方法的具體用法?Golang Context.Get怎麽用?Golang Context.Get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/raphael/goa.Context
的用法示例。
在下文中一共展示了Context.Get方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: NewDeleteAccountContext
// NewDeleteAccountContext parses the incoming request URL and body, performs validations and creates the
// context used by the account controller delete action.
func NewDeleteAccountContext(c *goa.Context) (*DeleteAccountContext, error) {
var err error
ctx := DeleteAccountContext{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)
}
return &ctx, err
}
示例4: NewListSeriesContext
// NewListSeriesContext parses the incoming request URL and body, performs validations and creates the
// context used by the series controller list action.
func NewListSeriesContext(c *goa.Context) (*ListSeriesContext, error) {
var err error
ctx := ListSeriesContext{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)
}
}
return &ctx, err
}
示例5:
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("Payload", func() {
It("returns nil if not initialized", func() {
Ω(ctx.Payload()).Should(BeNil())
})
})
示例6:
BeforeEach(func() {
var err error
r, err = http.NewRequest("GET", "/foo", nil)
Ω(err).ShouldNot(HaveOccurred())
rw = new(TestResponseWriter)
id := httprouter.Param{Key: "id", Value: "42"}
query := httprouter.Param{Key: "sort", Value: "asc"}
p = httprouter.Params{id, query}
})
JustBeforeEach(func() {
httpHandle(rw, r, p)
})
It("creates a handle that handles the request", func() {
i, ok := ctx.Get("id")
Ω(ok).Should(BeTrue())
Ω(i).Should(Equal("42"))
s, ok := ctx.Get("sort")
Ω(ok).Should(BeTrue())
Ω(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))
示例7:
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, ok := ctx.Get("foo")
Ω(p).Should(Equal(""))
Ω(ok).Should(BeFalse())
})
})
Describe("GetMany", func() {
It("returns nil if not initialized", func() {
Ω(ctx.GetMany("foo")).Should(BeNil())
})
})
Describe("Payload", func() {
It("returns nil if not initialized", func() {
Ω(ctx.Payload()).Should(BeNil())
})
示例8:
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))
})