DMarlon Studio

Advanced Go course

For those who know the basics: the techniques used in real projects. In DMarlon Studio, Go is the server of the Web (Go) target: you design the screens and the studio generates the Go server that serves them.

Start
  1. 1Interfaces and implicit implementationDefine interfaces in Go and see how a type satisfies one just by having its methods, with no implements keyword: carriers and shipping costs.Lesson 1
  2. 2Empty interface and type switchesStore values of any type with any (interface{}) in Go and get the concrete type back with type assertions and type switches.Lesson 2
  3. 3Embedding and compositionCompose types in Go by embedding structs: promoted fields and methods, overriding a method, and why it is not inheritance. Customers and addresses.Lesson 3
  4. 4Stringer and formatting your typesDecide how your Go types print with a String method (fmt.Stringer) and see what %v, %+v, %#v, %d and widths do with them.Lesson 4
  5. 5Custom errors, Is, As and %wCreate sentinel errors and your own error types in Go, wrap them with %w and recognise them later with errors.Is and errors.As.Lesson 5
  6. 6defer, panic and recoverPostpone calls with defer, see in which order they run, and turn a panic into an ordinary error with recover, in Go.Lesson 6
  7. 7Closures and function valuesUse functions as values in Go: function types, functions that return closures, and closures with their own state. Price rules and invoices.Lesson 7
  8. 8Generics: type parameters and constraintsWrite generic functions in Go with type parameters and constraints: one Sum for several number types and one Map for any type.Lesson 8
  9. 9A generic stackBuild a generic Stack[T] type in Go with Push, Pop and Len, and use it with strings and with integers: an editor's undo history.Lesson 9
  10. 10sort.Slice and sort.InterfaceSort structs in Go with sort.Slice, sort.SliceStable and sort.Interface, flip the order with sort.Reverse and search with sort.Search.Lesson 10
  11. 11Goroutines and WaitGroupRun work in parallel with goroutines in Go, wait for them to finish with sync.WaitGroup, and still get the same output every time.Lesson 11
  12. 12ChannelsConnect goroutines in Go with channels: send and receive, close a channel, loop over it with range and build a two-stage pipeline.Lesson 12
  13. 13Buffered channels and selectUse buffered channels as queues in Go, send without blocking using select and default, and set a time limit with select and time.After.Lesson 13
  14. 14Worker poolsShare work among a fixed number of goroutines in Go with a jobs channel and a results channel, and sort the results before printing them.Lesson 14
  15. 15Mutex and shared stateProtect data shared by several goroutines in Go with sync.Mutex: 55 buyers, 40 tickets and not one ticket sold twice.Lesson 15
  16. 16context: timeouts and cancellationPut a time limit on an operation and cancel it with context in Go: WithTimeout, WithCancel, ctx.Done() and ctx.Err() with a slow supplier.Lesson 16
  17. 17encoding/json and struct tagsTurn structs into JSON and back in Go with json.Marshal and json.Unmarshal, and control key names with tags such as omitempty and -.Lesson 17
  18. 18Table-driven checksCheck a Go function with a table of cases, just like go test does: each case with a name, an input and an expected result.Lesson 18
  19. 19HTTP handlers and httptestWrite an HTTP handler in Go with net/http that answers in JSON, and test it with httptest, no network or server. This is how the Web (Go) target works.Lesson 19
  20. 20Project: processing ordersA project that brings Go topics together: orders in JSON, a generic function that works in parallel with goroutines, and a type with String.Lesson 20