WebAPI made with Golang and Gin WebAPI framework
- Golang 1.23.x
- ROR core: https://github.com/NorskHelsenett/ror
Bash commands is from <repo root>
go get ./...
- Open the repository in Visual Studio Code
- Go to Debugging
- On "Run and debug" select "Debug ROR-Api" or "Debug ROR-Api tests"
go run main.go
Foreach 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 --parseInternal
the 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-static
make 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.0
For development with auto-reload:
go install github.com/cosmtrek/air@latest
make dev
For comprehensive linting:
make install-tools # Installs golangci-lint
make lint
Configuration is in .golangci.yml
.