Giter Site home page Giter Site logo

go-micro-services's Introduction

HTTP up front, Protobufs in the rear.

An demonstration of Golang micro-services that accept HTTP/JSON requests at API level and then leverage gRPC for inter-service communication.

new_sequence

The API Endpoint accepts HTTP requests at micro.demo:8080 and then spawns a number of RPC requests to the backend services.

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.

Installation

Protobuf v3 are required:

$ brew install protobuf --devel

Install the protoc-gen libraries:

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

Clone the repository:

$ git clone [email protected]:harlow/go-micro-services.git

If changes are made to the Protocol Buffers a Make file can be used to regenerate:

$ make pb

Bootstrap the services

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

$ make build
$ make run

Grab the Docker IP Address:

docker-machine ls

Note: in the examples below http://micro.demo is aliased to the Docker IP Address.

Curl the endpoint with an invalid auth token:

$ curl http://micro.demo:8080 -H "Authorization: Bearer INVALID_TOKEN"
Unauthorized

Curl the endpoint without checkin or checkout dates:

$ curl "http://micro.demo:8080?inDate=2015-04-09" -H "Authorization: Bearer VALID_TOKEN"
Please specify outDate

Curl the API endpoint with a valid auth token:

$ curl "http://micro.demo:8080?inDate=2015-04-09&outDate=2015-04-10" -H "Authorization: Bearer VALID_TOKEN"

The JSON response:

{
    "hotels": [
        {
            "id": 1,
            "name": "Clift Hotel",
            "phoneNumber": "(415) 775-4700",
            "description": "A 6-minute walk from Union Square and 4 minutes from a Muni Metro station, this luxury hotel designed by Philippe Starck features an artsy furniture collection in the lobby, including work by Salvador Dali.",
            "address": {
                "streetNumber": "495",
                "streetName": "Geary St",
                "city": "San Francisco",
                "state": "CA",
                "country": "United States",
                "postalCode": "94102"
            }
        }
    ],
    "ratePlans": [
        {
            "hotelId": 1,
            "code": "RACK",
            "inDate": "2015-04-09",
            "outDate": "2015-04-10",
            "roomType": {
                "bookableRate": 109,
                "totalRate": 109,
                "totalRateInclusive": 123.17,
                "code": "KNG"
            }
        }
    ]
}

Tracing Information

apitrace

gRPC tracing information:

http://micro.demo:8080/debug/requests
http://micro.demo:8080/debug/events

Credits

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

go-micro-services's People

Contributors

harlow avatar isaiah avatar jesselucas avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.