valyala / fasthttp

Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http
MIT License
21.66k stars 1.75k forks source link

can someone help refresh my memory how to declare a new ctx variable? invalid memory address or nil pointer dereference. #1459

Closed kolinfluence closed 1 year ago

kolinfluence commented 1 year ago

sorry, been a long time since i last used fasthttp but hope for a standard answer. thx in advance. i just need it this way instead of the AcquireRequest or AcquireResponse. is this possible to declare a new ctx *fasthttp.RequestCtx

basically what am i missing to "init" it?

invalid memory address or nil pointer dereference

    var ctx *fasthttp.RequestCtx
    ctx.Request.Header.Set("hello", "123")
li-jin-gou commented 1 year ago

use ctx.Init to prepares ctx. https://github.com/valyala/fasthttp/blob/9b4a7e5bf47a1eb88ae933352a32db983e49abb8/server.go#L2687-L2725

kolinfluence commented 1 year ago

@li-jin-gou thx.