Stupid Gopher Tricks
summary
Shows concrete tricks that actually compile and have been used: use anonymous structs for one-off JSON and template payloads and embed a mutex in an anonymous struct to keep globals clean; take method values to pass bound receivers into sync.Once or register HTTP handlers; use the atomic package and read how atomic.Value stores interface words — it works but panics if you store different concrete types; spawn subprocess tests to isolate profiling and use go list -f plus graphviz to emit dependency SVGs.
AI-written summary · about
chapters (18)
- 0:00Intro
- 1:51Anonymous structs template data
- 4:40Anonymous structs test cases (1/2)
- 5:15Anonymous structs test cases (2/2) You can go a step further and put the composite train the range statement itsel
- 5:34Embedded fields
- 6:27Anonymous structs embedded mutex
- 8:58Anonymous interfaces
- 10:07Method values A method value is what you get when you evaluate a method as an expression
- 12:16Method values: sync. Once The sync. Once type used to perform a task once with concurrency safety
- 14:00Method values: HTTP handlers
- 14:50Method values another example in package os/exec, the Ond type implement methods to set up
- 15:50Comparable types The Gospec defines a set of types as comparable
- 17:42Comparable types and map keys Any comparable type may be used as a mapkey.
- 18:42Structs as map keys An example from the Go continuous build infrastructures
- 32:13Subprocess tests
- 34:01Subprocess benchmarks (1/2)
- 35:34Subprocess benchmarks (2/2)
- 44:38go list generating dependency graphs








