Go based grpc - grpc gateway micro service example

Overview

go-grpc-gateway-server

This repository provides an example for go based microservice. Go micro services developed based on gRPC protobuf's and also uses gRPC gateway as a reverse proxy to support JSON clients/requests.

Dev pre-requisites

  1. golang

    brew install go
    Note: Make sure to have go1.17.2 or latest
    
  2. Docker

    brew install docker
    

    or downlooad docker from here

  3. PgAdmin for Postgres DB, download and this is optional if you prefer cli

  4. Update env

    vi ~/.zshrc
    
    add below entries, save & exit.
    
    export GOPATH=$HOME/go
    export PATH=$PATH:$GOPATH/bin
    export GONOPROXY="github.com,gopkg.in,go.uber.org"
    
    source ~/.zshrc
    

Install protoc

If you have Homebrew (which you can get from https://brew.sh), just run:

brew install protobuf

If you see any error messages, run brew doctor, follow any recommended fixes, and try again. If it still fails, try instead:

brew upgrade protobuf

Alternately, run the following commands:

PROTOC_ZIP=protoc-3.14.0-osx-x86_64.zip
curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.14.0/$PROTOC_ZIP
sudo unzip -o $PROTOC_ZIP -d /usr/local bin/protoc
sudo unzip -o $PROTOC_ZIP -d /usr/local 'include/*'
rm -f $PROTOC_ZIP```
go install \
github.com/grpc-ecosystem/grpc-gateway/v2/[email protected] \
github.com/grpc-ecosystem/grpc-gateway/v2/[email protected] \
google.golang.org/protobuf/cmd/[email protected] \
google.golang.org/grpc/cmd/[email protected]

Note: Make sure protobuf's installed correctly by running protoc --version

Generate protobuf's

Note: Required this step only when you make changes to .proto file or introduce a new one

cd pkg/api

go generate ./...

(or) alternative try below in case you did not set GOPATH

env PATH="$HOME/go/bin:$PATH" go generate ./...

Following 3 files are auto generated ones with above command

api/test_api.pb.go
api/test_api.pb.gw.go
api/test_api_grpc.pb.go

Build and Run Docker

docker compose build

docker compose up

Instructions for Developers

How to add a new service & test?

This section demonstrates, how to add a new grpc gateway service, implement and test it in local.

Note: Follow naming standards from here: https://cloud.google.com/apis/design/naming_convention#method_names

####1. Add new proto changes Lets add a test api called SayHello to pkg/api/test_api.proto

// SayHello service generates a greeting message
rpc SayHello(SayHelloRequest) returns (SayHelloResponse) {
 option (google.api.http) = {
   post: "/v1/greet"
   body: "*"
 };
}

Add request SayHelloRequest & response SayHelloResponse objects declared above

// Request Message for greeting service
message SayHelloRequest {
string name = 1;
}

// Response Message for greeting service
message SayHelloResponse {
string msg = 1;
}

####2. generate protobufs

cd pkg/api

go generate ./...

(or) alternative try below in case you did not set GOPATH

env PATH="$HOME/go/bin:$PATH"

####3. Implement service handler

func (s *Server) SayHello(ctx context.Context, request *api.SayHelloRequest) (*api.SayHelloResponse, error) {

	s.Log.Info("Hit to SayHello service and Request=%s", request.Name)
	response := &api.SayHelloResponse{Msg: "Hello " + request.Name + "!!"}
	return response, nil
}

####4. Build, Deploy and Test

docker compose build

docker compose up
curl -X POST -d '{"name": "John Doe" }' -H 'Content-Type: application/json' 
http://localhost:9091/v1/greet

Response:

{"msg": "Hello John Doe!!"}
Owner
Suresh Yekasiri
Suresh Yekasiri
Grpc-gateway-map-null - gRPC Gateway test using nullable values in map

Demonstrate gRPC gateway behavior with nullable values in maps Using grpc-gatewa

null 1 Jan 6, 2022
The Durudex gateway combines all durudex services so that it can be used through a single gateway.

The Durudex gateway combines all durudex services so that it can be used through a single gateway.

null 11 May 7, 2022
Sagadt - gRPC based micro services POC

Sagadt gRPC based micro service POC development Tools gRPC gRPC gateway buf Prot

Andrei Silchankau 0 Jan 4, 2022
golang grpc+go-micro.v2 wraper

gomicro golang grpc+go-micro.v2 wrapper install protoc and golang plugins binaries https://github.com/civet148/protoc-plugins install protoc from sour

null 0 Dec 20, 2021
Raft-grpc-demo - Some example code for how to use Hashicorp's Raft implementation with gRPC

raft-grpc-example This is some example code for how to use Hashicorp's Raft impl

dougsong 1 Jan 4, 2022
Simple installation script for grpc-gateway

Grpc-Gateway-installation Grpc-gateway is a plugin of Google protocol buffer compiler, it reads the definitions from .proto file and generates a rever

null 0 Dec 16, 2021
Example GRPC service

Simple GRPC/REST API as a Knative Service. This repository contains a simple GRPC/REST API, which can be run as a Knative service. Local To run the se

Matt Moore 8 Jan 16, 2022
GRPC - Creating a gRPC service from scratch

#Go gRPC services course Creating a gRPC service from scratch Command line colle

Rafael Diaz Miles 1 Jan 2, 2022
Service that calls uzma24/project1 service, takes input from .txt file and prints JSON output returned from the service.

Service that calls uzma24/project1 service, takes input from .txt file and prints JSON output returned from the service. Program can take large input files.

null 0 Feb 6, 2022
The Go client to access APIs on the Micro Platform

This is the Go client to access APIs on the Micro Platform

Micro 4 Nov 9, 2021
A service registry and service discovery implemention for kitex based on etcd

kitex etcd Introduction kitexetcd is an implemention of service registry and service discovery for kitex based on etcd. Installation go get -u github.

null 4 Feb 18, 2022
Json to rpc example with envoy, go, grpc, nats

grpc-nats-envoy json to rpc example with envoy, go, grpc, redis This repo is a mirror of https://github.com/charlesonunze/grpc-redis-envoy-example It

Charles Onunze 1 Dec 7, 2021
A Realtime API Gateway used with NATS to build REST, real time, and RPC APIs, where all your clients are synchronized seamlessly.

Realtime API Gateway Synchronize Your Clients Visit Resgate.io for guides, live demos, and resources. Resgate is a Go project implementing a realtime

Resgate.io - Synchronize Your Clients 569 May 17, 2022
Super fault-tolerant gateway for HTTP clusters, written in Go. White paper for reference - https://github.com/gptankit/serviceq-paper

ServiceQ ServiceQ is a fault-tolerant gateway for HTTP clusters. It employs probabilistic routing to distribute load during partial cluster shutdown (

Ankit Gupta 66 Apr 14, 2022
Crank4go API Gateway Brief Introduction It is a Golang implementation of Crank4j

Crank4go API Gateway Brief Introduction It is a Golang implementation of Crank4j, which derived from Cranker. the follow introduction is quoted from t

null 124 May 16, 2022
Internet connectivity for your VPC-attached Lambda functions without a NAT Gateway

lambdaeip Internet connectivity for your VPC-attached Lambda functions without a NAT Gateway Background I occasionally have serverless applications th

Glass Echidna 21 Feb 12, 2022
Drop-in replacement for Go net/http when running in AWS Lambda & API Gateway

Package gateway provides a drop-in replacement for net/http's ListenAndServe for use in AWS Lambda & API Gateway, simply swap it out for gateway.Liste

Apex 619 May 10, 2022
the pluto is a gateway new time, high performance, high stable, high availability, easy to use

pluto the pluto is a gateway new time, high performance, high stable, high availability, easy to use Acknowledgments thanks nbio for providing low lev

mobus 2 Sep 19, 2021
All-in-one Network Gateway for Malware analysis

aio-gw [EXPERIMENTAL]: All-in-one Network Gateway for Malware analysis. currently at Alpha stage. HELP NEEDED: if you're keen to contribute to aio-gw,

Ali Mosajjal 2 Jan 30, 2022