
When we define a map, we have to define the type of key and value. Creating a map of maps is possible in GoLang. The map of maps or the nested map is those where the key-value pairs the values are also the maps.
#Golang maps godocs how to#
Add API Operation annotations in controller code This tutorial demonstrates how to create a map of maps in GoLang. use ginSwagger middleware to serve the API docs "./docs" // docs is generated by Swag CLI, you have to import it.ĭ = "Swagger Example API"ĭ = "This is a sample server Petstore server."ĭ = "" The generated code package docs exports SwaggerInfo variable which we can use to set the title, description, version, host and base path programatically. R.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))Īdditionally some general API info can be set dynamically. Grants read and write access to administrative informationĪccounts.POST(":id/images", c.UploadAccountImage) This is a sample server celler server. Add General API annotations in main.go code:. Import "/swaggo/gin-swagger/swaggerFiles" // swagger embed files Import "/swaggo/gin-swagger" // gin-swagger middleware After using swag init to generate Swagger 2.0 docs, import the following packages:. If your General API annotation do not live in main.go, you can let swag know with -g. Make sure to import the generated docs/docs.go so that your specific configuration gets init'ed.
For go's core library, check out net/http. In order to serve these files, you can utilize one of our supported plugins.This will parse your comments and generate the required files ( docs folder and docs/docs.go). Run swag init in the project's root folder which contains the main.go file.ExamplesĪdd comments to your API source code, See Declarative Comments Format. This allows you to quickly integrate with an existing Go project (using Swagger UI). We've created a variety of plugins for popular Go web frameworks. Swag converts Go annotations to Swagger Documentation 2.0. Automatically generate RESTful API documentation with Swagger 2.0 for Go.