Site icon Golang Libraries, Apps, Golang Jobs and Go Tutorials

A Golang Tutorial about a standard project structure with gRPC, SQL, and Dependency Injection

Golang gRPC Tutorial

As a passionate about scalable project structure with a robust NestJS background, when I began working with Go, I missed some of the default features of this framework, like configuration module, global services, database connection, dependencies injections, etc., so I asked myself if a can apply the same techniques in Golang without any framework and the simplicity of Go… and I got it!

Welcome to the first article of this series. Take a cafe because here we go!

We are going to create a basic login gRPC API, and when you finish, you will know how

Standard gRPC API features are implemented in Golang

like:

Server Configuration and start gRPC server:

Database and common project structure:

Basic login gRPC API with JWT and Evans CLI :

gRPC interceptors, global services, and private/public RPC methods guarded with JWT:

Protocol Buffer, Configuration, and start Golang gRPC server

We are going to start with Protocol Buffer with Buf and Makefile for automatization

Create the project folder workspace:

$ mkdir logic_grpc && cd logic_grpc

Install protocol buffer compiler protochere for more details

$ brew install protobuf
$ protoc --version # Ensure compiler version is 3+

Install Golang gRPC compiler plugins

$ go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.26
$ go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1

Update your PATH so that the protoc compiler can find the plugins:

$ export PATH="$PATH:$HOME/.local/bin"

Nice! now let’s define our protocol buffer file. Create a folder at the root level called api, and inside the folder, create a file named auth.proto and paste the following code.

The complete Golang Tutorial:

Exit mobile version