Skip to content

An example Go micro service environment build on the go-micro framework.

License

Notifications You must be signed in to change notification settings

popstr/micro-world

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Micro World

This is an example micro service environment build with Go using the go-micro framework.

The point of this repo is to show how simple it is to implement efficient and lean micro services using Go.

Services

The environment consists of 3 different services. One service faces the outside world while the other have their own responsibilities and does not communicate outside the (imagined) cluster.

API Service

This is a classic REST API built using Echo. It faces a (imagined) frontend application what wants to display a page with all information about a user given a user id. To gather this information, the API Service communicates with the other two services in this repo - Name Service and Email Service. This inter-service communication uses gRPC.

The one and only API endpoint this service has is:

GET http://localhost:8080/api/users/{userID}

Example reply:

{
  "users": {
    "1": {
      "firstName": "Mikael",
      "lastName": "Karlsson",
      "email": "micke@mymail.com"
    }
  }
}

The system currently has 3 users with user id's 1, 2 and 3.

Name Service

This service has one gRPC endpoint that returns the firstname and lastname of a user given one or more user id's.

Email Service

As you might have guessed by now, this service has one gRPC endpoint that returns the email address of a user given one or more user id's.

Prerequisites

Install Protobuf: https://micro.mu/docs/runtime.html#protobuf

Application Data

User databases for the Name and Email services are emulated using two .csv files, stored in the respective project's data folder.

Communication

The gRPC communication protocol is defined in the two .proto files, located in the proto folder. These files are used to generate the source code for implementing both the server and the client.

Each service can generate the files it requires. This is done using the Go Generate functionality.

I have made it simple to generate code for all services with one command using make. To generate all required source files, run this command in the project root folder:

make gen

To generate code for one service only, run this from the service's cmd folder:

go generate

Future Improvements

The intention is to keep this project simple. Future additions must therefore not obfuscate the original message too much.

Things I might add:

About

An example Go micro service environment build on the go-micro framework.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published