本文整理匯總了Golang中github.com/raphael/goa.Context.Request方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Request方法的具體用法?Golang Context.Request怎麽用?Golang Context.Request使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/raphael/goa.Context
的用法示例。
在下文中一共展示了Context.Request方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RequestResource
// RequestResource returns the resource targeted by the CORS request defined in ctx.
func (v Specification) RequestResource(ctx *goa.Context, origin string) *ResourceDefinition {
path := ctx.Request().URL.Path
var match *ResourceDefinition
for _, res := range v {
if res.OriginAllowed(origin) && res.PathMatches(path) {
if res.Check == nil || res.Check(ctx) {
match = res
break
}
}
}
return match
}
示例2: GetToken
// GetToken extracts the JWT token from the request if there is one.
func GetToken(ctx *goa.Context, spec *Specification) (token *jwt.Token, err error) {
var found bool
var tok string
header := ctx.Request().Header.Get(spec.TokenHeader)
if header != "" {
parts := strings.Split(header, " ")
if len(parts) != 2 || strings.ToLower(parts[0]) != "bearer" {
// This is an error
}
tok = parts[1]
found = true
}
if !found && spec.AllowParam {
tok = ctx.Request().URL.Query().Get(spec.TokenParam)
}
if tok == "" {
err = fmt.Errorf("no token")
return
}
token, err = jwt.Parse(tok, keyFuncWrapper(spec.ValidationFunc))
return
}
示例3:
})
It("sets the response writer and returns the previous one", func() {
rwo := ctx.SetResponseWriter(rw)
Ω(rwo).Should(BeNil())
rwo = ctx.SetResponseWriter(&TestResponseWriter{Status: 43})
Ω(rwo).ShouldNot(BeNil())
Ω(rwo).Should(BeAssignableToTypeOf(&TestResponseWriter{}))
trw := rwo.(*TestResponseWriter)
Ω(trw.Status).Should(Equal(42))
})
})
Describe("Request", func() {
It("returns nil if not initialized", func() {
Ω(ctx.Request()).Should(BeNil())
})
})
Describe("Header", func() {
It("returns nil if not initialized", func() {
Ω(ctx.Header()).Should(BeNil())
})
})
Describe("ResponseStatus", func() {
It("returns 0 if not initialized", func() {
Ω(ctx.ResponseStatus()).Should(Equal(0))
})
})