本文整理汇总了Golang中github.com/valyala/fasthttp.Cookie类的典型用法代码示例。如果您正苦于以下问题:Golang Cookie类的具体用法?Golang Cookie怎么用?Golang Cookie使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cookie类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: requestHandler
func requestHandler(ctx *fasthttp.RequestCtx) {
fmt.Fprintf(ctx, "Hello, world!\n\n")
fmt.Fprintf(ctx, "Request method is %q\n", ctx.Method())
fmt.Fprintf(ctx, "RequestURI is %q\n", ctx.RequestURI())
fmt.Fprintf(ctx, "Requested path is %q\n", ctx.Path())
fmt.Fprintf(ctx, "Host is %q\n", ctx.Host())
fmt.Fprintf(ctx, "Query string is %q\n", ctx.QueryArgs())
fmt.Fprintf(ctx, "User-Agent is %q\n", ctx.UserAgent())
fmt.Fprintf(ctx, "Connection has been established at %s\n", ctx.ConnTime())
fmt.Fprintf(ctx, "Request has been started at %s\n", ctx.Time())
fmt.Fprintf(ctx, "Serial request number for the current connection is %d\n", ctx.ConnRequestNum())
fmt.Fprintf(ctx, "Your ip is %q\n\n", ctx.RemoteIP())
fmt.Fprintf(ctx, "Raw request is:\n---CUT---\n%s\n---CUT---", &ctx.Request)
ctx.SetContentType("text/plain; charset=utf8")
// Set arbitrary headers
ctx.Response.Header.Set("X-My-Header", "my-header-value")
// Set cookies
var c fasthttp.Cookie
c.SetKey("cookie-name")
c.SetValue("cookie-value")
ctx.Response.Header.SetCookie(&c)
}
开发者ID:erikdubbelboer,项目名称:bpprof,代码行数:27,代码来源:test.go
示例2: Cookie
// Cookie implements `engine.Request#Cookie` function.
func (r *Request) Cookie(name string) (engine.Cookie, error) {
c := new(fasthttp.Cookie)
c.SetKey(name)
b := r.Request.Header.Cookie(name)
if b == nil {
return nil, echo.ErrCookieNotFound
}
c.ParseBytes(b)
return &Cookie{c}, nil
}
开发者ID:efimovalex,项目名称:EventKitAPI,代码行数:11,代码来源:request.go
示例3: Cookies
// Cookies implements `engine.Request#Cookies` function.
func (r *Request) Cookies() []engine.Cookie {
cookies := []engine.Cookie{}
r.Request.Header.VisitAllCookie(func(name, value []byte) {
c := new(fasthttp.Cookie)
c.SetKeyBytes(name)
c.SetValueBytes(value)
cookies = append(cookies, &Cookie{c})
})
return cookies
}
开发者ID:ZloyDyadka,项目名称:echo,代码行数:11,代码来源:request.go
示例4: Cookies
// Cookies implements `engine.Request#Cookies` function.
func (r *Request) Cookies() []engine.Cookie {
cookies := make([]engine.Cookie, 0)
r.Request.Header.VisitAllCookie(func(name, value []byte) {
c := new(fasthttp.Cookie)
c.SetKey(string(name))
c.ParseBytes(value)
cookies = append(cookies, &Cookie{c})
})
return cookies
}
开发者ID:amsokol,项目名称:openshift-golang-template,代码行数:11,代码来源:request.go
示例5: Cookies
// Cookies implements `engine.Request#Cookies` function.
func (r *Request) Cookies() []engine.Cookie {
var cookies []engine.Cookie
i := 0
r.Request.Header.VisitAllCookie(func(name, value []byte) {
c := new(fasthttp.Cookie)
c.SetKey(string(name))
c.ParseBytes(value)
cookies[i] = &Cookie{c}
})
return cookies
}
开发者ID:efimovalex,项目名称:EventKitAPI,代码行数:12,代码来源:request.go
示例6: TestResponseSetCookie
func TestResponseSetCookie(t *testing.T) {
c := new(fasthttp.RequestCtx)
res := NewResponse(c, log.New("test"))
cookie := new(fasthttp.Cookie)
cookie.SetKey("name")
cookie.SetValue("Jon Snow")
res.SetCookie(&Cookie{cookie})
c.Response.Header.SetCookie(cookie)
ck := new(fasthttp.Cookie)
ck.SetKey("name")
assert.True(t, c.Response.Header.Cookie(ck))
assert.Equal(t, "Jon Snow", string(ck.Value()))
}
开发者ID:ZloyDyadka,项目名称:echo,代码行数:13,代码来源:response_test.go
示例7: SetCookie
// SetCookie implements `engine.Response#SetCookie` function.
func (r *Response) SetCookie(c engine.Cookie) {
cookie := new(fasthttp.Cookie)
cookie.SetKey(c.Name())
cookie.SetValue(c.Value())
cookie.SetPath(c.Path())
cookie.SetDomain(c.Domain())
cookie.SetExpire(c.Expires())
cookie.SetSecure(c.Secure())
cookie.SetHTTPOnly(c.HTTPOnly())
r.Response.Header.SetCookie(cookie)
}
开发者ID:efimovalex,项目名称:EventKitAPI,代码行数:12,代码来源:response.go
注:本文中的github.com/valyala/fasthttp.Cookie类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论