I have a Go app which uses fasthttp to serve some API requests.
Whenever I call one of these APIs using curl
, everything works as expected. However, whenever I call the API from another Go application, I get the following error on my server output:
error when serving connection "127.0.0.1:8080"<->"127.0.0.1:58377": error when reading request headers: read tcp4 127.0.0.1:8080->127.0.0.1:58377: wsarecv: An existing connection was forcibly closed by the remote host.
This doesn't appear to have any negative affect on the server or client, but it leads me to believe that I may be doing something wrong that may give me problems in the future.
This is how I am calling the API:
func (c *codeAPI) DoGET(endpoint string) (api.CodeAPIResponse, error) {
req, err := http.NewRequest("GET", c.apiURL+endpoint, nil)
if err != nil {
return nil, err
}
req.Header.Set("Authorization", "Bearer "+strings.TrimSpace(c.ctx.Config.AuthKey))
resp, err := c.client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var body CodeAPIBody
err = json.NewDecoder(resp.Body).Decode(&body)
return body, err
}
Where client is created like so:
func NewCodeAPI(endpoint, authKey string) api.CodeAPI {
return &codeAPI{
client: &http.Client{
Timeout: time.Second * 10,
},
apiURL: endpoint,
}
}
Can this be resolved in some way, or is it something I don't need to be concerned about?