- Repository Pattern → used in Repository-Layer/Database layer inside the
internal/database
directory to make business logic and database layer logic decoupled. In future if needed just make the struct and implement theUserRepository
interface to the desired database (Postgres/Cassandra/MongoDb) such that there will be no need to make any changes in theUserService
Service layer. - Separation Of Concern (from SOLID) → there is a separation between the transportation layer gRPC and the Service layer and the repository layer
- Dependency Inversion Principle (from SOLID) → Dependency of
UserRepository
is injected in theUserService
to perform Db-calls. - Builder Pattern from Design Principles → used in the constructor of the
UserService
which itself configure the gRPC's Reflection and bind the PORT to the service. - Idiomatic practices encouraged by the Golang Community → efficient use of
maps
,slices
etc.
- UserService Proto Definition-
+-------------+--------------------+---------------------------+----------------------------+
| SERVICE | RPC | REQUEST TYPE | RESPONSE TYPE |
+-------------+--------------------+---------------------------+----------------------------+
| UserService | GetUserById | GetUserByIdRequest | GetUserByIdResponse |
| UserService | GetUsersListByIds | GetUsersListByIdsRequest | GetUsersListByIdsResponse |
| UserService | GetUsersByCriteria | GetUsersByCriteriaRequest | GetUsersByCriteriaResponse |
+-------------+--------------------+---------------------------+----------------------------+
- Available Proto Message Types-
+----------------------------+
| MESSAGE |
+----------------------------+
| GetUserByIdRequest |
| GetUserByIdResponse |
| GetUsersByCriteriaRequest |
| GetUsersByCriteriaResponse |
| GetUsersListByIdsRequest |
| GetUsersListByIdsResponse |
+----------------------------+
-
GetUserById RPC types-
- Request
+-------+------------+----------+ | FIELD | TYPE | REPEATED | +-------+------------+----------+ | id | TYPE_INT64 | false | +-------+------------+----------+
- Response
+-------+---------------------+----------+ | FIELD | TYPE | REPEATED | +-------+---------------------+----------+ | user | TYPE_MESSAGE (User) | false | +-------+---------------------+----------+
-
GetUsersListByIds RPC types-
- Request
+-------+------------+----------+ | FIELD | TYPE | REPEATED | +-------+------------+----------+ | ids | TYPE_INT64 | true | +-------+------------+----------+
- Response
+-------+---------------------+----------+ | FIELD | TYPE | REPEATED | +-------+---------------------+----------+ | users | TYPE_MESSAGE (User) | true | +-------+---------------------+----------+
-
GetUsersByCriteria RPC types-
- Request
+-------+---------------------------+----------+ | FIELD | TYPE | REPEATED | +-------+---------------------------+----------+ | type | TYPE_ENUM (UserCriterias) | false | | value | TYPE_STRING | false | +-------+---------------------------+----------+
- Response
+-------+---------------------+----------+ | FIELD | TYPE | REPEATED | +-------+---------------------+----------+ | users | TYPE_MESSAGE (User) | true | +-------+---------------------+----------+
For the request and response of RPC calls checkout the user_service.proto
To run this project, The environment variable PORT
must be in the accessible scope which is used to set the port where the gRPC server will be listening for the incoming connections.
- Without Docker in Linux/WSL Environment:
make run
- will execute the source code.make build
- will build the executable binary from the source code.
- With Docker:
docker build . -t user-service
- will build image from Dockerfile.docker run -d --restart=always -p 8080:8080 user-service
- will run the image inside container.