WebAPI made with Golang and Gin WebAPI framework
- Golang 1.26
- Vault, Valkey, RabbitMQ, MongoDB, OpenIDConnect service (see requirements on how to start)
Bash commands is from <repo root>
To start the environment:
cp .env.example .env
docker compose up -dTo stop the environment:
docker compose downIf extra functionality is needed, the docker compose file is build with profiles.
The current available profiles are:
-
ui: provides mongoexpress and rediscommander
-
tracing: otel collector and jaeger
-
mocc: openid OIDC mocc
Docker compose profiles can be utilized like this:
Single profiles:
docker compose --profile ui up -ddocker compose --profile tracing up -ddocker compose --profile mocc up -dOr multiple profiles:
docker compose --profile ui,tracing,mocc up -dTo bring profiled docker compose manifests down, use the following:
docker compose --profile ui downdocker compose --profile tracing downdocker compose --profile mocc downOr multiple profiles:
docker compose --profile ui,tracing,mocc downFailure to do so will result in the containers related to that profile to keep running.
- Open the repository in Visual Studio Code
- Go to Debugging
- On "Run and debug" select "Debug ROR-Api"
go run cmd/api/main.goForeach endpoint function, you must add comments for it to show in generated openapi spec
ex:
// @Summary Create cluster
// @Schemes
// @Description Create a cluster
// @Tags cluster
// @Accept application/json
// @Produce application/json
// @Success 200 {object} responses.ClusterResponse
// @Failure 403 {string} Forbidden
// @Failure 401 {string} Unauthorized
// @Failure 500 {string} Failure message
// @Router /v1/cluster [post]
// @Security ApiKey || AccessToken
func Create() gin.HandlerFunc {
return func(c *gin.Context) {
...
}
}To generate new swagger you need to install a cmd called swag (https://github.com/swaggo/swag):
go install github.com/swaggo/swag/cmd/swag@latest(and remember to set <userprofile>\go\bin in PATH to terminal)
And run this command from ror-api root:
swag init -g cmd/api/main.go --parseDependency --output internal/docs --parseInternalthe folder docs and docs\swagger.json and docs\swagger.yaml is updated/created
This project includes a comprehensive Makefile that provides a standardized way to build, test, and deploy the application. Run make help to see all available targets.
# Setup the project for development
make setup
# Build the application
make build
# Run tests
make test
# Run the application locally
make run# Build and test everything
make all
# Run with auto-reload for development
make dev
# Format, lint, and run security checks
make quality
# Run tests with coverage
make test-coverage
# Generate Swagger documentation
make swagger
# Build for production (static binary)
make build-staticmake check-prereqs- Check all required tools are installedmake install-tools- Install development tools (golangci-lint, gosec, swag)
make build- Build the applicationmake build-generator- Build the generator applicationmake build-static- Build with static linking for containersmake test- Run all testsmake test-coverage- Run tests with coverage reportmake test-race- Run tests with race detectionmake bench- Run benchmarks
make fmt- Format Go codemake vet- Run go vetmake lint- Run golangci-lintmake gosec- Run security analysismake quality- Run all quality checks
make run- Run the API servermake run-generator- Run the generatormake dev- Run with auto-reload (requires air)make docs- Generate documentation
make docker-build- Build Docker image
make helm-install- Install with Helmmake helm-template- Generate Helm templates
make clean- Remove build artifactsmake deps- Download and verify dependenciesmake version- Show version information
The Makefile supports several environment variables:
# Docker registry for pushing images
export DOCKER_REGISTRY=your-registry.com
# Override Docker image name and tag
export DOCKER_IMAGE=custom-ror-api
export DOCKER_TAG=v1.0.0For development with auto-reload:
go install github.com/cosmtrek/air@latest
make devFor comprehensive linting:
make install-tools # Installs golangci-lint
make lintConfiguration is in .golangci.yml.
See LICENSE for details.