本文整理匯總了Golang中github.com/raphael/goa.Context.RawPayload方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.RawPayload方法的具體用法?Golang Context.RawPayload怎麽用?Golang Context.RawPayload使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/raphael/goa.Context
的用法示例。
在下文中一共展示了Context.RawPayload方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
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())
})
})
Context("with a request response", func() {
const appName = "foo"
var app goa.Service
const resName = "res"
const actName = "act"
var handler, unmarshaler goa.Handler
const reqBody = `"body"`
const respStatus = 200
var respContent = []byte("response")
var handleFunc goa.HandleFunc
var rw http.ResponseWriter
var request *http.Request
示例2:
})
})
})
Context("with different payload types", func() {
content := []byte(`{"hello": "world"}`)
decodedContent := map[string]interface{}{"hello": "world"}
BeforeEach(func() {
r.Header.Set("Content-Type", "application/json")
r.Body = ioutil.NopCloser(bytes.NewReader(content))
r.ContentLength = int64(len(content))
})
It("should work with application/json and load properly", func() {
Ω(ctx.RawPayload()).Should(Equal(decodedContent))
})
Context("with an empty Content-Type", func() {
BeforeEach(func() {
delete(r.Header, "Content-Type")
})
It("defaults to application/json and loads properly for JSON bodies", func() {
Ω(ctx.RawPayload()).Should(Equal(decodedContent))
})
})
Context("with a Content-Type of 'application/octet-stream' or any other", func() {
BeforeEach(func() {
r.Header.Set("Content-Type", "application/octet-stream")