BinaryGame Rooms Microservice
The rooms
service is a microservice responsible for managing game rooms in the distributed game. It handles room creation, user assignments, and room status updates.
Table of Contents
Features
- Room creation
- User assignments to rooms
- Room status updates
Requirements
- Go 1.22+
- Valkey (an open-source distribution of Redis)
Installation
-
Clone the repository:
git clone https://gitlab.com/binarygame/microservices/rooms.git
cd rooms
-
Install the dependencies:
go mod tidy
Configuration
Configure the service by setting the following environment variables:
ROOMS_SERVICE_HOST
: The host for the rooms service. Default: 0.0.0.0
.
ROOMS_SERVICE_PORT
: The port for the rooms service. Default: 8000
.
VALKEY_SERVICE_HOST
: The host for the Valkey service. Default: localhost
.
VALKEY_SERVICE_PORT
: The port for the Valkey service. Default: 6379
.
LOG_LEVEL
: The logging level for the service. Default: DEBUG
.
OTEL_COLLECTOR_HOST
(optional): The host for the OpenTelemetry collector.
OTEL_COLLECTOR_PORT
(optional): The port for the OpenTelemetry collector.
You can set these variables in a .env
file or export them directly in your shell.
Usage
-
Run the development server:
go run cmd/rooms/main.go
-
The service will be available at http://localhost:8000
.
Calling the API with grpcurl
You can use grpcurl
to call the service. For example, to create a room:
grpcurl -plaintext -d '{"hostId": "xyz", "name": "a room name", "maxPlayers": 2}' localhost:8000 connectrpc.rooms.v1.RoomsService.CreateRoom
Building Image Builds Locally
This project makes use of Earthly to build container images and for local testing binaries.
Build project with binary output at build/app
:
earthly +build
Build project with images as output:
# This command outputs the image names for your testing
earthly +build-image
Deploy
On this project, Earthly is used to build and publish the images on Gitlab's built-in Container Registry.
The following tags are available from this system:
latest
tags:
latest
: latest production build (alias: latest-production
)
latest-staging
: latest staging build
latest-development
: latest development build (git version)
latest-mr-<Merge Request ID>
: latest build from a specific merge request.
- The merge request id is the internal variant.
Commit-specific tags:
<Short Commit Hash>-production
: Available for all commits in the production branch.
<Short Commit Hash>-staging
: Available for all commits in the staging branch.
<Short Commit Hash>-development
: Available for all commits in the development branch.
Testing
To run the tests, use the following command:
go test ./...
Alternatively, you can use gotestsum
to run the tests with summarized output:
go run gotest.tools/gotestsum@latest
Ensure you have the test dependencies installed.
Contributing
- Fork the repository.
- Create a new branch:
git checkout -b feature/your-feature-name
.
- Make your changes and commit them:
git commit -m 'Add some feature'
.
- Push to the branch:
git push origin feature/your-feature-name
.
- Open a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Credits
- Project icon designed by
lutfix
from Flaticon.