Learning path

Structs and interfaces

Structs, methods, pointers, interfaces, embedding, errors and generics.

9 lessons · 14 challenges

  1. Lesson 1 challenge Structs Group related values into your own type with named fields.
  2. Lesson 2 challenges Methods and Receivers Attach functions to a type and choose between value and pointer receivers.
  3. Lesson 2 challenges Pointers Use & and * to share a value instead of copying it.
  4. Lesson 2 challenges Interfaces Describe behavior with an interface that any type can satisfy.
  5. Lesson 2 challenges Struct Embedding and Composition Reuse fields and methods by embedding one struct in another.
  6. Lesson 1 challenge Temperature Converter Convert between Celsius and Fahrenheit with your own number types.
  7. Lesson 2 challenges Error Handling Return errors as values, wrap them with context and check them with errors.Is and errors.As.
  8. Lesson 1 challenge Bank Account with Errors Model deposits and withdrawals that can fail with your own error types.
  9. Lesson 1 challenge Generics Write one function or type that works with many types using type parameters.