github.com/micro/go-micro/examples@v0.0.0-20210105173217-bf4ab679e18b/booking/README.md (about) 1 # Booking.com Example 2 3 This is [@harlow](https://github.com/harlow)'s [go-micro-services](https://github.com/harlow/go-micro-services) example converted to use Micro. 4 5 His README (with required changes): 6 7 The API Endpoint accepts HTTP requests at `localhost:8080` and then spawns a number of RPC requests to the backend services. 8 9 _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. 10 11 ### Setup 12 13 Docker is required for running the services https://docs.docker.com/engine/installation. 14 15 Protobuf v3 are required: 16 17 $ brew install protobuf 18 19 Install the protoc-gen libraries and other dependencies: 20 21 $ go get -u github.com/golang/protobuf/{proto,protoc-gen-go} 22 $ go get -u github.com/micro/protoc-gen-micro 23 $ go get -u github.com/micro/go-micro 24 $ go get -u github.com/hailocab/go-geoindex 25 26 Clone the repository: 27 28 $ git clone git@github.com:micro/micro.git 29 30 Change to examples dir 31 32 $ cd micro/go-micro/examples/booking 33 34 ### Protobufs 35 36 If changes are made to the Protocol Buffer files use the Makefile to regenerate: 37 38 $ make proto 39 40 ### Run 41 42 To make the demo as straigforward as possible; [Docker Compose](https://docs.docker.com/compose/) is used to run all the services at once (In a production environment each of the services would be run (and scaled) independently). 43 44 $ make build 45 $ make run 46 47 Curl the endpoint with an invalid auth token: 48 49 $ curl -H 'Content-Type: application/json' \ 50 -H "Authorization: Bearer INVALID_TOKEN" \ 51 -d '{"inDate": "2015-04-09"}' \ 52 http://localhost:8080/hotel/rates 53 54 {"id":"api.hotel.rates","code":401,"detail":"Unauthorized","status":"Unauthorized"} 55 56 Curl the endpoint without checkin or checkout dates: 57 58 $ curl -H 'Content-Type: application/json' \ 59 -H "Authorization: Bearer VALID_TOKEN" \ 60 -d '{"inDate": "2015-04-09"}' \ 61 http://localhost:8080/hotel/rates 62 63 {"id":"api.hotel.rates","code":400,"detail":"Please specify inDate/outDate params","status":"Bad Request"} 64 65 Curl the API endpoint with a valid auth token: 66 67 $ curl -H 'Content-Type: application/json' \ 68 -H "Authorization: Bearer VALID_TOKEN" \ 69 -d '{"inDate": "2015-04-09", "outDate": "2015-04-10"}' \ 70 http://localhost:8080/hotel/rates 71 72 The JSON response: 73 74 ```json 75 { 76 "hotels": [ 77 { 78 "id": 1, 79 "name": "Clift Hotel", 80 "phoneNumber": "(415) 775-4700", 81 "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.", 82 "address": { 83 "streetNumber": "495", 84 "streetName": "Geary St", 85 "city": "San Francisco", 86 "state": "CA", 87 "country": "United States", 88 "postalCode": "94102" 89 } 90 } 91 ], 92 "ratePlans": [ 93 { 94 "hotelId": 1, 95 "code": "RACK", 96 "inDate": "2015-04-09", 97 "outDate": "2015-04-10", 98 "roomType": { 99 "bookableRate": 109, 100 "totalRate": 109, 101 "totalRateInclusive": 123.17, 102 "code": "KNG" 103 } 104 } 105 ] 106 } 107 ```