Questions tagged [fasthttp]

Go HTTP implementation with a focus on performance. Use this for tags about using the fasthttp API.

53 questions
48
votes
1 answer

Why is fasthttp faster than net/http?

A fasthttp based server is up to 10 times faster than net/http. Which implementation details make fasthttp so much faster? Moreover, how does it manage incoming requests better than net/http?
Amit Verma
  • 749
  • 2
  • 7
  • 17
5
votes
2 answers

Fasthttp + fasthttprouter, trying to write middleware

I'm currently trying to write some middleware to work with fasthttp and fasthttprouter. And I'm stuck. func jwt(h fasthttprouter.Handle) fasthttprouter.Handle { myfunc := func(ctx *fasthttp.RequestCtx, _ fasthttprouter.Params) { …
user2515948
4
votes
1 answer

Correct use of fasthttp.Client combined with goroutines

I am new to Go and am looking for the correct way of using net/http or fasthttp with goroutines. Unfortunately there are not many fasthttp client examples out there. I found the following code: (Example1) package main import ( "bufio" …
ChrisG
  • 202
  • 2
  • 13
4
votes
1 answer

Get arbitary request header value in golang fasthttp

Searched through docs and read source, could not find anyway to access something like ctx.Request.Header.Get("X-Forwarded-For") I see in header.go, the type RequestHeader struct is defined something like h []argsKV bufKV argsKV cookies…
est
  • 11,429
  • 14
  • 70
  • 118
4
votes
4 answers

Get a request parameter key-value in fasthttp

http://127.0.0.1:8080/x?haha=1 I want to get something like ctx.QueryArgs().Get("haha") is it possible in golang's fasthttp package?
est
  • 11,429
  • 14
  • 70
  • 118
3
votes
1 answer

How to get all headers in array

I tried to get all headers in handler and faced some difficulties. valyala/fasthttp has the needed methods and I can get headlines one by one, but I don`t see the obvious way to get all of the headers. So, How can I get all of the headers into an…
BlackFox
  • 33
  • 5
3
votes
1 answer

Golang fasthttp very slow with request

I am building a Rest API with fasthttp package. I have a test route that I am using to measure performance: package main import ( "github.com/valyala/fasthttp" "runtime" ) func main() { runtime.GOMAXPROCS(8) m := func(ctx…
jrkt
  • 2,615
  • 5
  • 28
  • 48
2
votes
1 answer

golang replace fasthttp to gin with slice bounds out of range runtime error

looking into a httpserver and see if it is possible to change from fasthttp to gin but stuck and having a runtime error during routing from middleware. I am trying to keep the code similar to each other if possible. main.go func main() { ... …
Simon
  • 411
  • 6
  • 11
2
votes
1 answer

How to read Query Params in fasthttp without URL decoding

I am processing a GET request in Go using fasthttp. The query parameter test in this request is .%2A%2Ftoday%2F.%2A. I am using POSTMAN to create the request, and the URL generated…
Alzio
  • 45
  • 9
2
votes
0 answers

High Average Request Duration on Digitalocean Load balancer using golang fasthttp

I have a go program which takes requests processes them within 100ms and sends a response. I am using digitalocean Load Balancer and i noticed 'Average Request Duration' is pretty high around 33Kms.Below is the…
rithik r
  • 191
  • 1
  • 1
  • 5
2
votes
1 answer

Response header settings is not working for the error case

ctx.Response.Header.Set function is not working for the error case. Please check the below code, package main import "fmt" import "github.com/valyala/fasthttp" func main() { requestHandler := func(ctx *fasthttp.RequestCtx) { …
sprabhakaran
  • 1,615
  • 5
  • 20
  • 36
2
votes
1 answer

How to get the header content from *fasthttp.Request of Golang?

As the title says , is there an api for that? *fasthttp.Request.Header.key When I call the method with POSTMAN , I can't get the header content key as the above code . Why
Mike
  • 419
  • 1
  • 6
  • 16
2
votes
1 answer

Testing fasthttp with httptest

I am wondering how I can test an application that's written with fasthttp using the httptest package in the base library of Go. I found this guide which explains the testing pretty well, but the issue is that httptest does not satisfy the…
Tigraine
  • 23,358
  • 11
  • 65
  • 110
1
vote
2 answers

How to make a GET request in Go Fiber to an API endpoint?

How to make a GET request in GO Fiber. I saw Fiber client but there is no working example code there. Could anyone kindly show me how to do that? suppose there is a API endpoint https://jsonplaceholder.typicode.com/posts How can I get the data from…
javmah
  • 99
  • 2
  • 6
1
vote
2 answers

How to pass an URL to a fasthttp-router, in Golang?

The application consists in outputting a bash command to a buffer. The catch: the arguments are urls. Which is working for simple cases, like: "duckduckgo". I.e., http://localhost:8080/free-riding/duckduckgo works perfectly. Output: …
BuddhiLW
  • 608
  • 3
  • 9
1
2 3 4