hands-on lab

Creating a Microservice in Go - Part 1

Difficulty: Intermediate
Duration: Up to 1 hour and 30 minutes
Students: 433
Rating: 4.2/5
Get guided in a real environmentPractice with a step-by-step scenario in a real, provisioned environment.
Learn and validateUse validations to check your solutions every step of the way.
See resultsTrack your knowledge and monitor your progress.

Description

You have a small collection of retro video games and you want to build a microservice API to manage them. In the spirit of microservices, you want to keeping the code base to one entity, games. This microservice will provide functionality to create, get, view, and delete a game entity. Within this lab, you will implement the functionality to create and view these entities. It will also be RESTFUL (reading and writing JSON), and provide endpoints to return a collection of games.

Learning Objectives

Upon completion of this lab you will be able to:

  • Understand Go code basics of creating a web server and connecting to a database
  • Implement web server code and SQL code to create entities in a database
  • Implement web server code and SQL code to retrieve entities from a database

Intended Audience

This lab is intended for:

  • Developers, especially those working with Go
  • Anyone leveraging containers

Prerequisites

You should possess:

  • Basic understanding of the Go programming language
  • Familiarity with basic SQL commands
  • Understanding of the Linux command line
  • Experience with JSON and CRUD APIs is recommended but not required

The following content is sufficient to fulfill these prerequisites:

Updates

October 4th, 2021 - Made the command to rebuild and run the api server explicit in the Retrieving Data From the Database lab step

August 15th, 2021 - Increased lab duration

May 26th, 2021 - Added instructions to include imports in the handler.go file as needed when they are not automatically added

Covered topics

Lab steps

Connecting to the Go Development Environment
Testing the Go API Server
Understanding the Database and Data
Understanding the Routing, Handlers, and Web Server
Implementing the CREATE Operation
Retrieving Data From the Database
Retrieving All the Games