Questions tagged [go-http]

This tag is for questions related to Go's HTTP package

Go's net/http package provides HTTP client and server implementations.

121 questions
2
votes
1 answer

Why can't Golang download certain webpages?

I want to download Fantasy Football Data to analyse in Go, but when I try to download from this api page then I get back an empty response, even though the code works for other websites, e.g. this api page Minimal reproduction, outputs an empty…
J Mead
  • 63
  • 5
1
vote
0 answers

go - Are "http.Transport" and "http.Client" safe for concurrent modification in Go?

According to http.Client and http.Transport documentation in Go's built-in net/http package: // The Client's Transport typically has internal state (cached TCP // connections), so Clients should be reused instead of created as // needed. Clients are…
Colduction
  • 103
  • 7
1
vote
0 answers

How can I simultaneously listen on multiple sets of ports with different routes and control their open/close status in Go?

In a recent project, I came across a requirement to simultaneously listen on multiple sets of ports with different routes, and have the ability to control the open/close status of each listening group. I aim to achieve this functionality using only…
lvyonghuan
  • 21
  • 1
1
vote
1 answer

Imagekit - Golang | How to use Context

Im trying to upload images from my Golang backend to imagekit via the imagekit sdk. Im facing problems with understanding what the context api is used for. Currently I don't really use context in my backend and pass all dependencies in the…
pirmin_b
  • 27
  • 8
1
vote
0 answers

AWS GO SDK returns "AuthFailure: AWS was not able to validate the provided access credentials"

I am developing a simple automation tool using a Go Fiber HTTP server to start and stop AWS instances using the Go SDK v1.44.156. The service listens to an endpoint at /csm/aws/:region/:instance_id/powerOn. My code works well when I send requests…
1
vote
0 answers

Is it right when I use the method "mux.HandleFunc()"

I'm a green hand with Go. I have a problem with this code.` package main import ( "fmt" "log" "net/http" ) func main() { mux := http.NewServeMux() mux.HandleFunc("/", homePage) mux.HandleFunc("/ws", wsEndpoint) if err :=…
David Lee
  • 11
  • 1
1
vote
1 answer

Golang follow orginal http method

I am trying to call an API so the thing is when I am trying to call it from Postman with "Follow original HTTP method" on it's working fine but on disabling it giving a 400-Bad request response. The same thing I am trying to do in my Go code with…
aakash singh
  • 267
  • 5
  • 19
1
vote
1 answer

Make a attendance table for students with Go

I'm trying to create a Student Attendance web app. Currently have a struct type Student struct { StudentID int StudentName string Created time.Time } All student will be listed on list.html func ListStudent(w http.ResponseWriter, r…
1
vote
1 answer

docker image for elasticsearch and golang error: unsupported protocol scheme ""

I am running an api using elasticsearch, go, and docker. I have an image for elasticsearch, and an image for the HTTP server scheme. I should be able to run docker-compose up, however for whatever reason, the web image is never ran successfully, and…
1
vote
1 answer

Go - After request headers are set, request body is empty

To create an outgoing POST request, func NewRequest() from net/http library is used. request body is parsed as a param. After request is created I set request headers using Set() func. After setting headers, request body is empty. // create a new…
1
vote
1 answer

Unable to create a handler that responds with error in Go to cause a retry

I am trying to verify if the go-retryablehttp execution performs retries as per the specified config. The verification methodology is to create a test that creates a retryable client creates a new request creates a new server with the error…
Ronak Agrawal
  • 1,006
  • 1
  • 19
  • 48
1
vote
2 answers

Go json manipulation

Hey there just started to transform my python code to Go, but have some issue on the json manipulations... here is my code so far package test import ( "encoding/json" "fmt" "io/ioutil" "net/http" "strings" "time" ) type…
itasli
  • 23
  • 6
1
vote
0 answers

Log error returned in ServeHTTP with custom logger

I am using Go Chi with a custom handler function that returns an error. Ideally I want to write a middleware function that uses my custom handler function and return an error that will eventually need to be handled. I will either handle the error in…
Corbuk
  • 670
  • 1
  • 8
  • 23
1
vote
0 answers

Go HTTP RoundTripper: Preventing Connection Reuse Based on Response

I have a use case where I want to use an HTTP client in Go with pooled connections (connection re-use), but with the special case where a connection is intentionally closed (not allowed for re-use) if a request on that connection returns a specific…
Jordan
  • 3,998
  • 9
  • 45
  • 81
1
vote
1 answer

Go HTTP idle connection pool and http trace

I have a long running GO program(version 1.18) which sends hundreds of GET requests simultaneously per second using RESTY to the remote https://api.abcd.com. Each GET request is a separate go-routine which uses the same RESTY client. remote server…
1 2
3
8 9