adding Println statements in golang stdlib
- install go bootstrap: https://storage.googleapis.com/golang/go1.4-bootstrap-20161024.tar.gz
- build it ( note the directory it says at the end of installation), in my case:
Installed Go for darwin/amd64 in /Users/geo/bootstrapped-go
- clone go repo: https://go.googlesource.com/go
- check out the version you’re interested in, in my case go1.7.4
- go to src folder
- GOROOT_BOOTSTRAP=/Users/boostrapped-go ./make.bash
- add your Println statements where needed
- any time you modify something in stdlib, you need to recompile
- repeat until problem found
chrome and chunked responses
Had an issue when trying to react to a chunked response from a server. The onreadystatechange function was being called only at the end, and not for intermediate values. Found the answer here:
- turns out, you need to set the header X-Content-Type-Options to nosniff
postgresql timeout
Found a really interesting bit of info in this heroku article:
Which would ensure your queries will be timed out after 30 seconds.
golang goqu ignore struct field
Problem: unexported struct field was used in a goqu query. The field did not have an equivalent db column.
Solution: mark it like in JSON:
golang switch case fallthrough
TIL: in go, a switch cases don’t automatically fallthrough. So, this:
won’t work as intended. Instead it should be:
golang debug specific test from compiled binary
Problem: want to debug a failing test, from a compiled binary containing a lot of other tests.
Solution:
- compile tests with go test -c
- run dlv: dlv exec ./my.test – -test.run SomePattern
- debug!
golang blank struct when unmarshalling json
TIL: if you have a struct with unexported fields ( aka lowercase field names ), and you try to unmarshal it from another package, the result will be a struct with blank field names.
golang database column tags
Comes in handy when you want a struct field to map to a db column, which may have a different name. For example, I have CreatedAt field, but in the db, it’s created_at: