Member-only story

Automate gRPC-Gateway project generation in Go with gen-grpc-gateway-api

Abhishek koserwal
4 min readMay 22, 2024

--

When it comes to developing modern APIs, gRPC and gRPC-Gateway are the go-to solutions for building high-performance services with the added benefit of flexible RESTful interfaces. This blog post will walk you through setting up a gRPC-Gateway sample project in Golang using the gen-grpc-gateway-api project.

What is gRPC-Gateway?

gRPC-Gateway is a plugin for the Google protocol buffers compiler that generates a reverse proxy server. This server translates a RESTful HTTP API into gRPC, allowing you to maintain the performance benefits of gRPC while offering REST's ease of use and ubiquity.

Prerequisites

Before starting, ensure you have the following installed:

  • Golang (1.22.3 or later)
  • Protocol Buffers Compiler (protoc)

Project Overview: gen-grpc-gateway-api

The gen-grpc-gateway-api The project is designed to simplify the setup of a gRPC-Gateway in Golang. This project is also listed on the related projects section: https://grpc-ecosystem.github.io/grpc-gateway/docs/related_projects/

Project gen-grpc-gateway-api consists of:

gen-grpc.sh: A shell script that can be used to generate a Go project that utilizes the gRPC-gateway and protobuf to expose a simple API. By using the gen-grpc.shgenerator, you can quickly get started with the gRPC gateway.

git clone https://github.com/akoserwal/gen-grpc-gateway-api.git

Run the script to generate a sample project

./gen-grpc-gateway-api/gen-grpc.sh

It will prompt for user inputs:

  1. Project name: <name of project director>
  2. Domain name: <golang module domain: github.com/$DOMAIN_NAME/
  3. Enter service name (e.g., Greeter): Name of the proto

Let's proceed with the generation process:

Enter the project name


Enter project name: test

Enter the domain name

Enter domain name: akoserwal

Based on the inputs, the script will run 'go mod init' in the directory 'test'. The output can be seen in…

--

--

Abhishek koserwal
Abhishek koserwal

Written by Abhishek koserwal

#redhatter #opensource #developer #kubernetes #keycloak #golang #openshift #quarkus #spring

No responses yet

Write a response