10 Habits tracker using gRPC

 

This chapter covers

  • Writing a web service using Protobuf and generating the Go code of its gRPC definition
  • Using the Context interface in Go
  • Running the service with basic endpoints
  • Testing with integration tests

As developers, we spend most of our work day in front of a screen, and spend leisure activity time there too. Unfortunately, the effects of a high number of hours watching these lit pixels—albeit sometimes positive for moral or psychological aspects—are mostly considered negative for eyesight, causing eye fatigue, dry eyes, or difficulty focusing. On the other hand, there are some activities that will alleviate these ophthalmic conditions—most of them include simply doing something other than watching a screen. Usually, recommendations go along the path of regularly taking a stroll, reading a book, or engaging in physical activity.

It’s never easy to pick up a new habit, and no one has ever gone from never jogging to running a marathon. The goal is always achieved incrementally. But the important point is to track how much of these habits we can develop in a week, and maybe adjust objectives for the next week.

10.1 API definition

10.1.1 Protobuf declaration

10.1.2 Code generation

10.2 Empty service

10.2.1 Creating a small logger

10.2.2 Server structure

10.2.3 Creating and running the server

10.3 First endpoint: Create

10.3.1 Business layer

10.3.2 API layer

10.3.3 Data retention

10.4 Unit testing with generated mocks

10.4.1 Generate mocks

10.4.2 Use the mocks

10.5 Integration testing

10.5.1 List habits

10.5.2 Integration with go test

10.6 Getting the best out of the context

10.6.1 What is a context?