Skip to content

Latest commit

 

History

History
46 lines (35 loc) · 1.65 KB

README.md

File metadata and controls

46 lines (35 loc) · 1.65 KB

grpc-twitter-example

Usage

go get github.com/crowdint/grpc-twitter-example

Run the server:

$ go run server/main.go

Run the client:

$ go run client/main.go

You should see something like:

ID:7 text:"One dog rolled before him, well-nigh slashed in half; but a second had him by the thigh, a third gripped his collar be- hind, and a fourth h" user:<ID:1 >
ID:19 text:"Near it in the field, I remember, were three faint points of light, three telescopic stars infinitely remote, and all around it was the unfa" user:<ID:1 >
ID:1 text:"Near it in the field, I remember, were three faint points of light, three telescopic stars infinitely remote, and all around it was the unfa" user:<ID:1 >
ID:9 text:"The secular cooling that must someday overtake our planet has already gone far indeed with our neighbour.It was at this time that the meetin" user:<ID:1 >
ID:3 text:"The Nellie, a cruising yawl, swung to her anchor without a flutter of the sails, and was at rest.One dog rolled before him, well-nigh slashe" user:<ID:1 >

Got 5 tweets

Web front-end example

This example demonstrates an HTTP front-end, using gin, which connects to the backend Twitter server via grpc.

$ go run frontend/main.go
[GIN-debug] GET   /tweets/:user_id          --> main.func·001 (3 handlers)
[GIN-debug] Listening and serving HTTP on :8080

Now, let's do some twittering!

$ curl -v -d '{"text": "a tweet!", "userId": 1}' -H "Content-Type: application/json" -XPOST http://localhost:8080/tweet/1
[...]
< HTTP/1.1 204 No Content

$ curl http://localhost:8080/tweets/1
[{"text":"a tweet!","user":{"ID":1}}]