DMarlon Studio

Go course

Simple and concurrent: web servers, command-line tools and cloud services.

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.

Basic Go course

20 lessons

From scratch: everything you need to write your first programs.

  1. 1Hello, worldWrite your first Go program: package main, the main function and fmt.Println to show text and numbers in the console.Lesson 1
  2. 2Variables and typesStore data in Go variables with var and :=, meet the basic types (int, float64, string and bool) and the zero value of each one.Lesson 2
  3. 3Constants and arithmeticUse constants and iota in Go, calculate with + - * / and %, and convert between int and float64 so you keep the decimals.Lesson 3
  4. 4Strings and PrintfJoin strings with + and format output in Go with fmt.Printf and fmt.Sprintf: the %s, %d, %.2f, %v and %q verbs, and column widths.Lesson 4
  5. 5Reading inputRead lines from the keyboard in Go with bufio.Scanner and turn them into numbers with strconv.Atoi and strconv.ParseFloat to do maths.Lesson 5
  6. 6If and elseMake decisions in Go with if, else if and else, combine conditions with &&, || and !, and use the if statement's init part.Lesson 6
  7. 7Choosing with switchChoose between several cases with switch in Go: several values per case, default, switch with no expression, init statement and fallthrough.Lesson 7
  8. 8For loopsRepeat code in Go with for, the language's only loop: the classic form, as a while, with no condition at all, break and continue.Lesson 8
  9. 9ArraysStore several values of one type in a Go array: fixed length, indexes, len, looping with for, copying on assignment and comparing with ==.Lesson 9
  10. 10SlicesWork with slices in Go, the lists that grow: append, len, cap, make and s[a:b] slicing that shares memory with the original.Lesson 10
  11. 11MapsStore key-value pairs in a Go map: adding, reading with ok, delete and len, and printing it in the same order every time with sort.Strings.Lesson 11
  12. 12Functions and multiple resultsWrite Go functions with parameters and a result type, return several values at once and use named results.Lesson 12
  13. 13Errors as valuesTreat errors as values in Go: create them with errors.New and fmt.Errorf, check them with if err != nil and recognise them with errors.Is.Lesson 13
  14. 14StructsGroup related data into a Go struct: fields, literals by name or by order, %+v, copies and slices of structs.Lesson 14
  15. 15MethodsAdd methods to your own Go types: value and pointer receivers, and the String() method that decides how a value is printed.Lesson 15
  16. 16PointersUnderstand pointers in Go: & to get an address, * to reach the value, functions that change the original, and nil.Lesson 16
  17. 17The strings and strconv packagesWork with text in Go using the strings package (Split, TrimSpace, Join, Contains, Replace) and convert text and numbers with strconv.Lesson 17
  18. 18Looping with rangeLoop over slices, maps and strings in Go with for and range: index and value, keys sorted with sort.Strings, and runes for characters.Lesson 18
  19. 19Writing and reading filesWrite and read text files in Go with the os package: WriteFile, OpenFile to append, Open with bufio.Scanner, and defer to close.Lesson 19
  20. 20Project: a shop inventoryThe final project of the basic Go course: a shop inventory built with structs, methods, errors, slices, loops and Printf.Lesson 20

For those who know the basics: the techniques used in real projects.

  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