This is the backend for the Arcadia game. It is written in GoLang and uses the Gin framework for HTTP serving.
- docker (To contribute you will also need go, swag and golangci-lint)
proceed sequentially from here and run applicable commands
-
Clone the Repository.
-
cp .env.example .env
and change values, if necessary. -
cp config.example.json config.json
and change values, if necessary.
-
Enable git hooks by running
git config core.hooksPath .githooks
. -
Configure .vscode/settings.json to use golangci-lint for linting.
{
"go.lintTool":"golangci-lint",
"go.lintFlags": [
"--fast"
],
"go.lintOnSave": "package",
"go.formatTool": "goimports",
"go.useLanguageServer": true,
"[go]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
},
"go.docsTool": "gogetdoc"
}
-
Run
go mod download
to download all go dependencies. -
Ensure you have a MySQL database running and create a database with the name you specified in
.env
andconfig.json
.
-
Uncomment and comment the appropriate lines in
docker-compose.yaml
-
Make changes to
.env
(set APP_ENV to DEV) andconfig.json
(copy over from DOCKER config). -
Follow all subsequent steps in the "Only for Docker" section below.
-
docker compose up --build
-
Access Adminer at http://localhost:8080/ (or at the ADMINER_EXTERNAL_PORT)
-
MySQL volumes are present in ./docker_volumes/mysql/ and logs at ./docker_volumes/logs/
-
Create and restore MySQL dumps with the scripts in ./scripts/
-
docker compose down
to stop all containers
- To seed the database with dummy data, run
make seed
ormake docker_seed
-
Run
make watch
command to start the backend in development mode. This will automatically restart the backend when you make changes to the code. -
Run
make build
command to build the backend for production andmake start
to start the binary file (arcadia_server
).
-
All code should be formatted using
make lint
ormake fix
before committing. -
Commit messages should be according to Conventional Commits.
-
Use the Pull Request template when creating a PR.
-
All Testing functions should be of the form
<feature>-test.go
-
Include the test function(s) in
run_tests.go
-
Run
make test
ormake docker_test
to run all tests.
Note: Testing in this repo has been made Docker-friendly, so not all best practices for tests may apply (such as filename = *_test.go
or using the testing
package or go test -v ./...
)
-
Specify the URL in which you would like to have the docs in
config.SwaggerURL
-
Write comments above Controllers to make a OpenAPI docs for that route.
-
Refer swaggo/swag documentation and learn how to write comments above controllers.
-
Run
swag fmt
to format the comments -
Run
swag init
to build docs from the comments