Setting up utility functions and constants for the microservice
In this section, we will add all of the common functions and constants, if any, to the util.v
file. Let's say that we want our microservice to provide a custom JSON response that includes a status code and a descriptive message, whenever a request originates, to do the following:
- Retrieve record(s) that don't exist.
- Create or update a record with malformed JSON payloads in the request body.
- Create or update a
note
with a message that is not unique. - Update a record that doesn't exist.
To achieve this, in the util.v
file, we will add a struct, named CustomResponse
, that has a status
field to represent a status code and a message
field that provides descriptive details about the state of action being performed by the microservice endpoint, as follows:
// file: util.v module main import json struct CustomResponse { status int ...