With the server/client files created and properly positioned in our project, we will edit the UsersService microservice to provide the user data using the gRPC.
Refactoring is a common and constant process in microservices; we will modify the app.go file so that the search for users through the cache and database is more reusable. Currently, this search is within the getUser method in two large blocks of code.
The first block of code searches directly from the cache:
... if value, err := a.Cache.getValue(id); err == nil && len(value) != 0 { log.Println("from cache") w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) w.Write([]byte(value)) return } ...
The second code block searches ...