本文整理汇总了Golang中github.com/valyala/fasthttp.RequestCtx.URI方法的典型用法代码示例。如果您正苦于以下问题:Golang RequestCtx.URI方法的具体用法?Golang RequestCtx.URI怎么用?Golang RequestCtx.URI使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/valyala/fasthttp.RequestCtx
的用法示例。
在下文中一共展示了RequestCtx.URI方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewRequest
// NewRequest returns `Request` instance.
func NewRequest(c *fasthttp.RequestCtx, l *log.Logger) *Request {
return &Request{
RequestCtx: c,
url: &URL{URI: c.URI()},
header: &RequestHeader{RequestHeader: &c.Request.Header},
logger: l,
}
}
示例2: ServeHTTP
// ServeHTTP is called whenever there is a new request.
// This is quite similar to JavaEE Servlet interface.
func (h *MyHandler) ServeHTTP(ctx *fasthttp.RequestCtx) {
// In the future we can use requester can detect request spammers!
// requester := ctx.RemoteAddr()
// Increase request count
count := &(h.requests)
atomic.AddUint64(count, 1)
if ctx.IsGet() {
url := ctx.URI()
operations, format, err, invalid := ParseURI(url, h.imageSource, h.watermarker)
if err != nil {
ctx.NotFound()
logging.Debug(err)
return
}
if invalid != nil {
ctx.Error(invalid.Error(), 400)
return
}
blob, err := h.operator.GetBlob(operations...)
if err != nil {
ctx.NotFound()
logging.Debug(err)
} else {
ctx.SetContentType("image/" + format)
ctx.Write(blob)
logging.Debug("Blob returned")
}
} else if ctx.IsPost() {
// POST is currently unused so we can use this for testing
h.RetrieveHello(ctx)
logging.Debug("Post request received")
}
}
示例3: ServeHTTP
func (s *Server) ServeHTTP(c *fasthttp.RequestCtx) {
// Request
rq := s.pool.request.Get().(*Request)
reqHdr := s.pool.requestHeader.Get().(*RequestHeader)
reqURL := s.pool.url.Get().(*URL)
reqHdr.reset(&c.Request.Header)
reqURL.reset(c.URI())
rq.reset(c, reqHdr, reqURL)
// Response
rs := s.pool.response.Get().(*Response)
resHdr := s.pool.responseHeader.Get().(*ResponseHeader)
resHdr.reset(&c.Response.Header)
rs.reset(c, resHdr)
s.handler.ServeHTTP(rq, rs)
s.pool.request.Put(rq)
s.pool.requestHeader.Put(reqHdr)
s.pool.url.Put(reqURL)
s.pool.response.Put(rs)
s.pool.responseHeader.Put(resHdr)
}