Sunday, October 2, 2022
HomeGolangA Golang Tutorial about a regular venture construction with gRPC, SQL, and...

A Golang Tutorial about a regular venture construction with gRPC, SQL, and Dependency Injection


As a obsessed with scalable venture construction with a strong NestJS background, after I started working with Go, I missed a few of the default options of this framework, like configuration module, world providers, database connection, dependencies injections, and so on., so I requested myself if a can apply the identical methods in Golang with none framework and the simplicity of Go… and I obtained it!

Welcome to the primary article of this sequence. Take a restaurant as a result of right here we go!

We’re going to create a primary login gRPC API, and while you end, you’ll know the way

Normal gRPC API options are carried out in Golang

like:

Server Configuration and begin gRPC server:

  • Protocol Buffer with Buf and Makefile
  • Golang Server configuration with Viper
  • Begin gRPC server

Database and customary venture construction:

  • Use GORM to hook up with Postgres and migrate your fashions
  • Use Wire to handle dependencies
  • Create venture construction gRPC -> Service -> Repository -> DAO

Primary login gRPC API with JWT and Evans CLI :

  • Implement person creation
  • Use Evans CLI shopper for person creation
  • Implements Hash/Examine Password

gRPC interceptors, world providers, and personal/public RPC strategies guarded with JWT:

  • Implement interceptors(Authorization interceptor & logging interceptor)
  • Register private and non-private gRPC strategies with interceptors
  • Implements methodology service + JWT for guard gRPC methodology
  • Create a world service in utilizing context

Protocol Buffer, Configuration, and begin Golang gRPC server

We’re going to begin with Protocol Buffer with Buf and Makefile for automatization

Create the venture folder workspace:

$ mkdir logic_grpc && cd logic_grpc

Set up protocol buffer compiler protocright here for extra particulars

$ brew set up protobuf
$ protoc --version # Guarantee compiler model is 3+

Set up Golang gRPC compiler plugins

$ go set up google.golang.org/protobuf/cmd/[email protected]
$ go set up google.golang.org/grpc/cmd/[email protected]

Replace your PATH in order that the protoc compiler can discover the plugins:

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

Good! now let’s outline our protocol buffer file. Create a folder on the root stage known as api, and contained in the folder, create a file named auth.proto and paste the next code.

The entire Golang Tutorial:

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments