A mini-guide: Build a REST API as a Go microservice together with MySQL

Click for: original source

In this mini-tutorial, author creates a simple REST-API with a MySQL database. Author have recently found himself coding and deploying a lot of Go microservices and this is his experience and advice. By Johan Lejdung.

The article deals with:

  • Setup the API – routing
  • Database connection – using go-sql-driver
  • Structs & Dependencies
  • Database Migrations

This coupled with a docker-compose file – containing the database – makes development on multiple machines dead-simple. An undeployable microservice is of no use, therefore author added a Dockerfile to package the application for easy distribution.

The built image is a mere 10MB! The code is available in GitHub repo. Short and sweet!

[Read More]

Tags golang apis mysql containers docker microservices