Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/piyoki/grpc-go-demo
A quick gRPC demo written in Golang
https://github.com/piyoki/grpc-go-demo
api container golang grpc grpc-go microservices
Last synced: about 1 month ago
JSON representation
A quick gRPC demo written in Golang
- Host: GitHub
- URL: https://github.com/piyoki/grpc-go-demo
- Owner: piyoki
- License: mit
- Created: 2021-04-16T13:04:01.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-04-19T11:19:05.000Z (over 3 years ago)
- Last Synced: 2024-07-03T15:46:59.431Z (6 months ago)
- Topics: api, container, golang, grpc, grpc-go, microservices
- Language: Go
- Homepage:
- Size: 17.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gRPC Go Demo
## gRPC Introduction
Remote Procedure Calls are something that we use within distributed systems that allow us to communicate between applications. More specifically, it allows us to expose methods within our application that we want other applications to be able to invoke.
It’s similar to REST API communication in the sense that with it, you are effectively exposing functionality within your app to other apps using a HTTP connection as the communication medium.
## Differences between gRPC and REST
Whilst REST and gRPC are somewhat similar, there are some fundamental differences in how they work that you should be aware of.
1. gRPC utilizes `HTTP/2` whereas REST utilizes `HTTP 1.1`
2. gRPC utilizes the protocol buffer data format as opposed to the standard JSON data format that is typically used within REST APIs
3. With gRPC you can utilize `HTTP/2` capabilities such as server-side streaming, client-side streaming or even bidirectional-streaming should you wish.## Prerequisites
You may need to have the following installed on your local machine:
```bash
# Install protobuff compiler
$ sudo apt install protobuf-compiler
# Check Version
$ protoc --version # Ensure compiler version is 3+
# Install protoc-gen-go
$ go get -u google.golang.org/grpc # install grpc library
$ go get google.golang.org/protobuf/cmd/protoc-gen-go \
google.golang.org/grpc/cmd/protoc-gen-go-grpc
```You will have to ensure that `$GOPATH/bin` is on your environment path so that you can use the `protoc` tool later on in this tutorial.
Add the following lines to your `.bashrc` or `.zshrc` file```bash
export GOPATH=$(go env GOPATH)
export PATH=$PATH:$GOPATH/bin
```## Run the Demo
Spins up the server
```bash
go run server.go
```Initiate a client connection and send a message to the server
```bash
go run client/client.go
```## Reference
[gRPC Offical Documentation](https://grpc.io/docs/languages/go/quickstart/)