-
Let's try to create closer to real world gRPC microservice with tracing and monitoring 👋: Source code u can find here Core tools used what will be used: 🚀 PostgreSQL as database Redis for sessions and caching Jaeger open source, end-to-end distributed tracing Prometheus monitoring and alerting Grafana for to compose observability dashboards with everything from Prometheus
-
SaaSHub
SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives
-
validator
:100:Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving
Then we usually have to validate request input, for errors gRPC has packages status and codes I found good practice to parse and log errors in handler layer, here i use ParseGRPCErrStatusCode method, which parse err and returns matched gRPC code. Validator is good solution for validation.
-
Every app must be covered by tests, I didn't completely cover all code this one, but wrote some test of course. For testing and mocking testify and gomock is very good tools.
-
Setup postgres and redis Usually production SQL db standard solution for these days is combination of sqlx and pgx. Good Redis Go clients is go-redis and redigo, i used first.
-
I found this is very good gRPC Middleware repository, but we easy can create our own, for example logger interceptor:
-
I like to use evans for simple testing gRPC.
-
In cmd folder let's init all dependencies and start the app. Viper is very good and common choice as complete configuration solution for Go applications. We use here config-local.yml file approach.
-
Next let's create logger, here i used Uber's Zap under the hood, important here is to create Logger interface for be able to replace logger in the future if it's need.
Related posts
-
Just released a maintained github.com/davecgh/go-spew/spew fork
-
logrus.errorf() causes panics?
-
Quickly and easily implement a high-performance e-commerce system by sponge+dtm
-
Building a RESTful API with Go Fiber: An Express-Inspired Boilerplate
-
Leverage Your Test Suite With testcontainers-go & docker-compose