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
0
votes
1 answer

golang passing data payload from HTTP client

I have an HTTPS endpoint that works fine with a cURL command like this: curl -k -u xyz:pqr \ --data "grant_type=client_credentials" \ https://my-url Now I am trying to use golang to call the same API endpoint like this: data :=…
Darth.Vader
  • 5,079
  • 7
  • 50
  • 90
0
votes
2 answers

Converting URL Params to JSON in Go with http.Request

I'm validating parameters made from a request, but unlike when the request is made in JSON, I'm not able to easily convert query params into it's struct counterpart. Using the…
Nicole Staline
  • 557
  • 4
  • 15
0
votes
1 answer

Converting a complex http json response array to a simple struct slice without creating several structs to match the response using Go

If an http response comes in a format that is not directly a list of objects the only way I could figure out how to convert them to structs is by creating two structs to match the exact format of the response. Is there anyway to do this cleaner…
Blake Rivell
  • 13,105
  • 31
  • 115
  • 231
0
votes
2 answers

Golang: Getting the response-redirect URL from an HTTP response

I'm trying to make a HTTP request using http.Get(url) in Go and I want to open the response in a browser. I'm using browser.OpenURL() to launch the system browser, but I cannot figure out how to obtain the response url. In Python, using the requests…
Кафка
  • 467
  • 4
  • 11
0
votes
2 answers

While using a single http client for several goroutines, does editing the transport on one thread affect the other?

Lets say I have a global net/http client in my program. Within this program, I have several goroutines making requests with the same global client. E.g. Golang Pseudocode: package main func editTransportAndFetch(c *http.Client) { c.Transport =…
0
votes
1 answer

How to serve static files from root URL

I am making simple web app using http/server and I use following code for handling routes (credit to this post): package retable import ( "context" "fmt" "net/http" "regexp" "strconv" "strings" ) var routes = []route{ …
Bodito
  • 97
  • 1
  • 14
0
votes
2 answers

How To Pull Secrets as Config File in Golang

So I am pretty new to Go and I am curious about how to import passwords and URLs dynamically without exposing them within my scripts. In python, I was able to implement this with a JSON payload and would basically import JSON, load the payload, and…
R. Barrett
  • 685
  • 11
  • 34
0
votes
1 answer

How do I set MaxConnsPerHost on http2 transport in GoLang

I'm trying to force GoLang to use HTTP2 and so have done the following: transport := &http2.Transport{} client := &http.Client{Transport: transport} But I also need to set MaxConnsPerHost and MaxIdleConns, which I'm not able to. I know I can set…
Chandraaditya
  • 341
  • 1
  • 8
  • 18
0
votes
1 answer

Streaming http response to http ResponseWriter

I want to stream an HTTP GET response to HTTP responsewriter. I have searched for the solution online and finally used io.Copy for that. But it's not streaming, instead, it is downloading the entire get response and then passing to HTTP…
0
votes
1 answer

Go Deep understanding of custom error handling in REST API

I am coming from the world of Node.js where I learn a lot from building web application using Express and there, there is a good way, I think, to handle when dealing with error and in case of unexpected error, there is a awesome way to catch it. So,…
Mael Fosso
  • 360
  • 6
  • 14
0
votes
2 answers

How to wrap a Go package with only a few modifications?

How can I write a Go package that wraps a library such that calls to overridden functions use my implementation, and non-overridden functions "fall through" to the library I am wrapping? In particular: I want my Go package to wrap net/http, except I…
jstrieb
  • 599
  • 1
  • 7
  • 20
0
votes
0 answers

Golang Two HTTP requests via one client

How to prepare two HTTP requests via one client on Go without problems with memory? I have the next code : func moduleView(url string) { var module Module httpClient := &http.Client{} moduleId, listHttpResponseCode :=…
0
votes
1 answer

HTTP client returns random errors on timeout

I have an HTTP client with a custom RoundTripper which in turn uses the http.DefaultTransport to handle the request. Now imagine I have a slow server which takes a long time to respond and it makes my http client timeout and cancel the client. Here…
2hamed
  • 8,719
  • 13
  • 69
  • 112
0
votes
0 answers

server panic when trying to implement qor dashboard with go-swagger generated api server

2021/02/12 17:17:56 Finish [GET] /admin Took 0.05ms 2021/02/12 17:17:56 http: panic serving 127.0.0.1:50746: runtime error: invalid memory address or nil pointer dereference goroutine 65 [running]: net/http.(*conn).serve.func1(0xc00076f040) …
0
votes
0 answers

How to set up httpClient with pfx certificate?

I am creating an application which will communicate with other systems via rest APIs with one .pfx certificate. I have to write this application in Go. Any leads will be extremely helpful.
1 2 3
8 9