Skip to content

prolog-opslab/go-micro-services

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Golang Microservices Example

An demonstration of Golang micro-services that accept HTTP/JSON requests at API level and then leverage gRPC for inter-service communication. The example application plots Hotel locations on a Google map:

screen shot 2016-11-07 at 9 31 12 pm

The web page makes an HTTP request to the API Endpoint which in turn spawns a number of RPC requests to the backend services.

reqseq

Note: Data for each of the services is stored in JSON flat files under the /data/ directory. In reality each of the services could choose their own specialty datastore. The Geo service for example could use PostGis or any other database specializing in geospacial queries.

Setup

Docker is required for running the services https://docs.docker.com/engine/installation.

Protobuf v3 are required:

$ brew install protobuf

Install the protoc-gen libraries:

$ go get -u github.com/golang/protobuf/{proto,protoc-gen-go}

Clone the repository:

$ git clone git@github.com:harlow/go-micro-services.git

Run

To make the demo as straigforward as possible; Docker Compose is used to run all the services at once (In a production environment each of the services would be run (and scaled) independently).

$ make run

Vist the web page in a browser:

http://localhost:5000/

cURL the API endpoint and receive GeoJSON response:

$ curl "http://localhost:8080/inventory?inDate=2015-04-09&outDate=2015-04-10" 

The JSON response:

{
	"type": "FeatureCollection",
	"features": [{
		"id": "5",
		"type": "Feature",
		"properties": {
			"name": "Phoenix Hotel",
			"phone_number": "(415) 776-1380"
		},
		"geometry": {
			"type": "Point",
			"coordinates": [-122.4181, 37.7831]
		}
	}, {
		"id": "3",
		"type": "Feature",
		"properties": {
			"name": "Hotel Zetta",
			"phone_number": "(415) 543-8555"
		},
		"geometry": {
			"type": "Point",
			"coordinates": [-122.4071, 37.7834]
		}
	}]
}

Protobufs

If changes are made to the Protocol Buffer files use the Makefile to regenerate:

$ make pb

Credits

Thanks to all the contributors. This codebase was heavily inspired by the following talks and repositories:

About

HTTP up front, Protobufs in the rear.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 96.9%
  • Makefile 2.1%
  • Shell 1.0%