More Golang notes

Http clients with net/http

The “easy” function is http.Get, but ofc you can’t provide a user-agent and stuff.

Configuration is split into “Client” (redirects, cookies, timeouts, etc) and “Transport” (compression, tls, etc). The transport is a field of the client. And the client can be reused (I think it’s more or less a bag of properties)

Pattern for configuring requests:

Decoding json

A lot of examples on the google will say to use json.Decoder. This is for json streaming, jsonlines, etc and is probably not what you want. json.Unmarshal is a better first thing to reach for; yeah, yeah, ok, you have to buffer the response in memory, what about it. Source.

ioutil

Apparently there was a module called ioutil that was deprecated. Everything in it (popular ones include Copy and ReadAll) was moved to io or os as appropriate.