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
-1
votes
3 answers

JSON body for POST request

I am building a body for a POST request relativeurl := "this-is-a-test-url" postBody := fmt.Sprintf("{\"requests\": [{\"httpMethod\": \"GET\",\"relativeUrl\": \"%s\"}]}", relativeurl) When I do a fmt.Println of postBody, I see: { "requests": [ …
-1
votes
1 answer

Golang fasthttp router custom logger

I'm playing with fasthttp and it's router, I have no issues with basic things, I have a working server and a router, that is the easy part. The issue is with the logger, I would like to be able to customize that one, but it does not seem possible…
night-gold
  • 2,202
  • 2
  • 20
  • 31
-1
votes
1 answer

golang http client returning wrong content type

I have a very simple Go program that performs HTTP HEAD on a URL, and prints the content-type of the response: package main import ( "fmt" "net/http" ) func main() { resp, _ :=…
Alex Glikson
  • 401
  • 4
  • 13
-1
votes
1 answer

Where does the serveHTTP utility come from on supposedly naked func

I have this utility: type Handler struct{} func (h Handler) Mount(router *mux.Router, v PeopleInjection) { router.HandleFunc("/api/v1/people", h.makeGetMany(v)).Methods("GET") } the above calls this: func (h Handler) makeGetMany(v…
user5047085
-2
votes
1 answer

How to reuse HTTP request instance in Go

I'm building an API that scrapes some data off a webpage. To do so, i need to send a GET request to a home page, scrape a 'RequestVerificationToken' from the HTML, then send another POST request to the same URL with a username, password, and the…
SumitN
  • 23
  • 3
-2
votes
1 answer

Superfluous WriteHeader and no response

I'm writing an HTTP API that sends requests to a WebSocket gateway. I'm using go1.14.7 and gorilla/mux v1.8.0. The code will be cross-compiled using GOOS=linux GOARCH=arm GOARM=7. My problems are the following: respondBadRequest() always logs this…
Steffen
  • 1,328
  • 3
  • 12
  • 29
-2
votes
1 answer

How do I make parallel http.Get queries

I'm trying to make http queries in parallel and then wait for all to finish: g1, _ := go http.Get('http://example.com/1') g2, _ := go http.Get('http://example.com/2') res1 := g1.wait() or { panic(err) } res2 := g2.wait() or { panic(err) } …
chovy
  • 72,281
  • 52
  • 227
  • 295
-2
votes
1 answer

How to maintain the same session using a cookie jar in Go

I am wondering how I can maintain the same session using a cookie jar in Go I have done this in JS using this method: const cookieJar = request.jar(); request({ headers: { //headers here }, url: url, jar: cookieJar method:…
Salvatore Timpani
  • 407
  • 3
  • 6
  • 26
-2
votes
1 answer

How to wrap http.Handler in method

The simplest way to get file system in go is the code below. http.Handle("/files", http.StripPrefix(pathPrefix, http.FileServer(root))) But for the purpose of objective design, I prefer to wrap the body of function in the method like this. f :=…
ccd
  • 5,788
  • 10
  • 46
  • 96
-2
votes
2 answers

Incoming requests: context with custom typed fields

I'm writing a more or less simple web application using go that provides a rest api. When a request comes in, I want to store the id of the user, which is part of the api token, temporarily inside the requests context. After reading some articles…
Tom
  • 4,070
  • 4
  • 22
  • 50
-2
votes
1 answer

Invalid Memory Address with http.SetCookie

I am working on an auth package called persona. Every thing works fine except one thing, when I try to set a cookie, I have an invalid memory address. func Signup(user interface{}, username string, w http.ResponseWriter) error { key :=…
Erwan ROUSSEL
  • 11
  • 1
  • 8
-3
votes
1 answer

html renderer in Golang without third party imports

I am self-teaching myself go and I have started experimenting with using go as a back end. I have the following code which renders HTML pages, but I am looking for a solution that doesn't rely on a third party import to get a better grasp of what is…
-3
votes
1 answer

Inconsistent key maps from r.URL.Query()

When parsing URLs using r.URL.Query(), I am getting inconsistent results and was wondering if anyone else has had the same issue and/or a viable workaround. Keys sometimes return ?keyName instead of keyName so often i'll do keys.Get on both…
Thor
  • 121
  • 6
-3
votes
1 answer

Sending HTTP Put body from ReadCloser never ends

Target I want to send to data to my server from a read closer. (In the example a NopCloser, later it will be the Stdout of an exec.Command) Problem The Request never ends. Even if I manually close the cmdOut the program nevers ends. Concrete: It…
Simon Frey
  • 2,539
  • 2
  • 11
  • 20
-4
votes
1 answer

Reuse Go http client

I want to make a get request for each param in an params array. The url is static. Is there a way to reuse my custom http client for each iteration? I don't want to reset the header for each request. Ideally, I'd like to do something like…
David
  • 303
  • 3
  • 8
  • 21
1 2 3
8
9