Golang How To Design And Build Rest Microservices In Go

All you need to integrate SQL & NoSQL databases, search engines and all the tools that you need in your REST API.

Last updated 2022-01-10 | 4.3

- How to structure and organize your microservice.
- Domain Driven Development.
- Hexagonal architecture applied.

What you'll learn

How to structure and organize your microservice.
Domain Driven Development.
Hexagonal architecture applied.
MySQL integration and configuration.
Integrate Cassandra DB in your microservices.
Elasticsearch integration and configuration.
Logging to standard output and log files.
DAO pattern implementation.
How to build
publish and use a custom Go library.
Testing all the layers of your application.
How dependencies work in Go.

* Requirements

* Just complete the Golang tour available at Golang's website
* Nice to have: Part 1 of this course

Description

  • How to structure and organize your microservice.
  • Domain Driven Development.
  • Hexagonal architecture applied.
  • MySQL integration and configuration.
  • Integrate Cassandra DB in your microservices.
  • Elasticsearch integration and configuration.
  • Logging to standard output and log files.
  • DAO pattern implementation.
  • How to build, publish and use a custom Go library.
  • Testing all the layers of your application.
  • How dependencies work in Go.

Course content

12 sections • 48 lectures

Course goal: What we're going to build Preview 07:34

A brief description about what we're going to build during this course.

A quick preview Preview 10:14

In this video we're looking at a quick preview on what we're going to build, the approaches, the technologies, the patterns, the tools, everything so you can have a good idea about what you're about to learn during this course.

These are all of the repos! Preview 00:31

In this lecture I'm just sharing the course repositories so you can take a look at them from day one. This is all we're going to do during this course! Don't feel overwhelmed, I can ensure you that by the end of this course you'll dominate all of this! Enjoy and let's Go :)

Create projects in Github Preview 13:19

Creating all of our projects in Github.

HTTP frameworks Preview 10:11

An introduction to HTTP frameworks in Go. We're using gin-gonic for both our Users and OAuth API and gorilla/mux for our Items API later.

Basic application structure: MVC pattern Preview 30:09

An introduction to the MVC pattern in Go.

Starting from our domain Preview 46:34

How and why we should always start from our domain and then going backwards in the layers.

How to structure our domain persistence Preview 41:07

How to structure the domain persistence layer: a kind introduction to the DAO pattern.

Working with dates Preview 21:04

How to work with dates in Go.

Configure MySQL client in Go Preview 29:38

Adding and configuring our MySQL database in Go.

How to insert rows Preview 26:41

How to insert rows in our MySQL database.

How to read rows Preview 14:58

How to read a single row from our MySQL server.

How to handle MySQL errors Preview 33:30

How to handle MySQL errors.

How to update rows Preview 33:38

How to update rows in our MySQL database.

How to delete rows Preview 21:42

How to delete rows from our MySQL database.

How to find rows Preview 51:42

How to find rows in our MySQL database.

How to marshal structs Preview 33:03

An introduction to the marshaller concept, how to develop and where to use it!

Services structure Preview 25:33

Implementing our services via interfaces so we have a consistent and mockeable business logic handler in our entire application.

No logging system Preview 38:07

Adding a logger to our application ( zap from Uber in this case).

OAuth authentication Preview 11:27

An introduction to OAuth authentication.

Domain Driven Development Preview 18:20

An introduction to Domain Driven Development.

DDD - Starting with the domain Preview 27:57

How to start working on the domain as the start point of our application development process.

DDD - Project structure Preview 36:26

How to implement our DDD approach in Go.

Introduction to Cassandra DB Preview 10:55

An introduction to CassandraDB.

Cassandra Go client Preview 22:10

An introduction to one of the Cassandra clients in Go.

How to insert, get and update records Preview 29:57

In this lesson we're interacting with our Cassandra cluster to insert, get and update records.

Tune our get session implementation Preview 05:50

In this lesson we're improving our GetSession() implementation based on recommendations from the Cassandra Go client.

Authenticating users Preview 11:27

How to authenticate users in our ecosystem by leveraging on the OAuth API.

Generating access tokens Preview 57:11

In this lesson we're looking at how to generate access tokens in our OAuth API. Please take a look at the external resources attached to this lesson so you can define the best approach that fits the best for your use cases.

Different requests for the two APIs Preview 15:36

In this lesson we're defining two different requests: One for our OAuth API and other for our Users API so you can create one based on the other one and not be restrained to the same interface.

Creating a shared OAuth library Preview 52:45

How to create an OAuth library in Github that we're going to use in all of our microservices to authenticate against our OAuth API.

How dependencies work: go modules Preview 24:37

An introduction to how dependencies work in Go and how we can use dep to generate and maintain our vendor folder.


GOROOT: Where Go is installed. Default: /usr/local/go

    export GOROOT=/usr/local/go

    export PATH=$PATH:$GOROOT/bin


GOPATH: Workspace for Go projects. Default: ~/go

    Go 1.13 set "modules" as the confirmed dependency system in Go.

    Go < 1.13: Every Go project must be cloned INSIDE of your GOPATH.

    Go >= 1.13: Every Go project using modules must be cloned OUTSIDE of your GOPATH.


Defining transitive dependencies Preview 06:31

How to explicitly define transitive dependencies in our libraries.

Creating a shared utils library Preview 26:41

How to create a Utils library in Github and use it in all of our projects.

Application structure: MVC & gorilla/mux Preview 47:00

Configure our mux router Preview 36:24

In this lesson we're configuring our Mux router in the Items API.

Introduction to Elasticsearch Preview 12:10

A kind introduction to ES.

Adding ElasticSearch client Preview 29:44

Adding the ES client in our Go application.

Index documents in ES Preview 38:58

In this lesson we're covering how to implement and organize our code in order to index new documents in ES.

Moving our logger to the utils library Preview 33:03

In this lesson we're removing the copies of the logger from all the repos and moving it to a common library that we can import and use.

Improving our errors library Preview 32:46

In this lesson we're improving the quality of our errors library.

Dependencies: Using modules in all projects Preview 22:23

In this lesson we're applying vendor to all of our projects and making them ready to ship.

How to get documents by ID Preview 36:13

Searching documents in ES Preview 44:46

In this lesson we're implementing both the get by id and search features in our API.

Homework: Add delete and update endpoints Preview 03:52

In this video I'm explaining the homework you have in order to add the delete and update endpoints to our API.

Testing our application: OAuth client Preview 28:15

In this lesson we're unit testing our OAuth library. I'll leave some exercises so you can continue testing the application.

Use Docker to ship our Items API Preview 23:59

In this lesson we're adding Docker to our Items API and make it available for usage via containers instead of locally running the app.

Extra class - Take a look at my website Preview 03:31

If you have any questions or comments that are not particularly about the topics treated during this course you can always use the Q&A section and I'll make sure you clear your doubts by publishing content about those topics or issues as well. If you like what you're looking and getting, take a look at my website, there is a lot more in there!