Skip to content

NorskHelsenett/ror-api

Repository files navigation

ROR-API

WebAPI made with Golang and Gin WebAPI framework

Prerequisites

Get started

Bash commands is from <repo root>

Download dependencies:

go get ./...

Start WebAPI

Visual Studio Code

  1. Open the repository in Visual Studio Code
  2. Go to Debugging
  3. On "Run and debug" select "Debug ROR-Api" or "Debug ROR-Api tests"

Terminal

go run main.go

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