Skip to content

Latest commit

 

History

History
96 lines (76 loc) · 2.97 KB

README.md

File metadata and controls

96 lines (76 loc) · 2.97 KB

Learn Go by Writing REST APIs

Miki Tebeka [email protected]

Abstract

In this hands-on workshop about getting started with the Go programming language. Learning will be done by writing some REST APIs. This class is for people who would like to get started with Go and have some experience in programming.

Chapters

  • In Setup we'll make sure you have all that is needed to complete the workshop
  • We'll start by writing the customary "Hello World" program
    • Program structure, import path, types
  • Now we can add some tests
    • Testing, declarations, if statement
  • Next we'll add ping & time handlers
    • HTTP protocol, REST overview
  • After that we'll set and get keys
    • map, slicing, byte arrays, defer
  • Then we'll return all the keys
    • slices, for loop, empty interface, JSON
  • We'll use gorilla/mux to simplify routing
    • go get
  • Finally we'll support concurrency
    • goroutines, locks, struct

Go Wild

The best way to learn a programming language is to find a problem and solve it using the language. If the problem is something that "itches" you - even better.

Here are some ideas on how to improve our web server:

  • Add a command line argument for the port to listen on
  • Support multiple databases
  • Instead of using a sync.Mutex to guard our data structure. Use a goroutine that will listen on a channel for commands and return result over a channel
  • Implement more commands, see redis commands for inspiration
  • Test everything
    • Including running the server and calling it over HTTP
  • ...

Examples

List of examples used in the lessons:

References

License

CC BY-NC-SA 4.0