/ror-api

The ROR API

Primary LanguageGoApache License 2.0Apache-2.0

ROR-API

Webapi made with Golang and Gin webapi framework

Prerequisites

Get started

Bash commands is from <repo root>/src/backend/ror-api/

Download dependencies:

go get ./...

Start webapi

go run main.go

Or Start the Debug ROR-Api debugger config from VS Code

Generate swagger docs:

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) {
		...
	}
}

Examples of annotations

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 cmd/api/docs

the folder docs and docs\swagger.json and docs\swagger.yaml is updated/created