本文整理汇总了Golang中github.com/valyala/fasthttp.RequestCtx.ConnTime方法的典型用法代码示例。如果您正苦于以下问题:Golang RequestCtx.ConnTime方法的具体用法?Golang RequestCtx.ConnTime怎么用?Golang RequestCtx.ConnTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/valyala/fasthttp.RequestCtx
的用法示例。
在下文中一共展示了RequestCtx.ConnTime方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: mainHandler
func mainHandler(ctx *fasthttp.RequestCtx) {
// Performance hack for prefork mode - periodically close keepalive
// connections for evenly distributing connections among available
// processes.
if *prefork {
maxDuration := maxConnDuration + time.Millisecond*time.Duration(atomic.LoadUint64(&connDurationJitter))
if time.Since(ctx.ConnTime()) > maxDuration {
atomic.StoreUint64(&connDurationJitter, uint64(rand.Intn(100)))
ctx.SetConnectionClose()
}
}
path := ctx.Path()
switch string(path) {
case "/plaintext":
plaintextHandler(ctx)
case "/json":
jsonHandler(ctx)
case "/db":
dbHandler(ctx)
case "/queries":
queriesHandler(ctx)
case "/fortune":
fortuneHandler(ctx)
case "/update":
updateHandler(ctx)
default:
ctx.Error("unexpected path", fasthttp.StatusBadRequest)
}
}
示例2: 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)
}