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.

67 questions
0
votes
2 answers

goroutine different behaviour for statement execution and function execution

Can anyone explain the difference between the following two calls regarding the goroutines? Method 1 fmt.Println("Starting srv") go LOGGER.Error(srv.ListenAndServe()) fmt.Println("Starting intSrv") go LOGGER.Error(intSrv.ListenAndServe()) This…
Mayuran
  • 589
  • 2
  • 4
  • 26
0
votes
1 answer

Displaying a pagination widget in Go

I am using HTML templating in Go to render a pagination widget. I am trying to follow an example of how to do it from here: https://www.solodev.com/blog/web-design/adding-pagination-to-your-website.stml This is my code so far: // Item size like call…
Lookas
  • 3
  • 4
0
votes
2 answers

How to unmarshal with different types of the same variable

Im working with the API with possibile output: [ { "contactId": 2, "email": "karina.plain@example.com", "markerName": "JavascriptEngine", "dataType": "String", "value": "Carakan", "dateEntered": "2013-01-03T14:52:00" }, { …
R.Slaby
  • 99
  • 2
  • 7
0
votes
0 answers

How to create a generic request validation middleware

What I want to achieve here is to create a very generic middleware called, Expects that actually validates the current request according to the parameters provided. It will raise a Bad Request if the required params are not present or are empty. In…
Ahmed Dhanani
  • 781
  • 1
  • 9
  • 28
0
votes
1 answer

Post Request with PostgreSQL and json-api returns an empty body

After a POST request, i was expecting to have a last inserted record marshalled into json, but instead returns an empty body. What am i not doing well? package models import ( "encoding/json" "errors" "flag" "fmt" "log" …
afidegnum
  • 121
  • 3
  • 18
0
votes
2 answers

"http.FileServer(http.Dir...))" not working in separate package

Directory tree: . ├── main.go └── web ├── app.go └── views ├── index.html └── js └── app.jsx This works: package main import ( "net/http" ) func main() { http.Handle("/",…
sean
  • 3,094
  • 5
  • 23
  • 41
-1
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…
-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
  • 1,814
  • 1
  • 14
  • 20
-1
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
  • 7,739
  • 11
  • 60
  • 102
-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
  • 351
  • 2
  • 10
-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

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
  • 783
  • 1
  • 6
  • 17
-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:…
-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
  • 2,488
  • 1
  • 15
  • 38
-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
  • 2,748
  • 2
  • 18
  • 36