Skip to content

Go R1 Day 71

progress🔗

  • Learn Go With Tests -> Using select with channels to wait for multiple goroutines.
  • Of particular interest is this:

Notice how we have to use make when creating a channel; rather than say var ch chan struct{}. When you use var the variable will be initialised with the "zero" value of the type. So for string it is "", int it is 0, etc. For channels the zero value is nil and if you try and send to it with <- it will block forever because you cannot send to nil channels (go-fundamentals-select listed below)

  • Used httptest to create mock server for faster testing, and included wrapper around a calls to allow configuration for timeout. This ensures that testing can handle in milliseconds, but default behavior in a deployment would be 10 seconds or more.