Generate Swagger/OpenAPI docs for a Go API by installing the swag CLI and running swag init to scan your code comments.
Generate Swagger/OpenAPI docs for a Go API by adding swag init to your project and running the command to scan your code for comments.
go install github.com/swaggo/swag/cmd/swag@latest
swag init -g main.go -o docs
The swag init command scans your Go source files (starting from main.go) for special comments, generates the docs/swagger.json and docs/swagger.yaml files, and creates a docs/doc.go file to serve the documentation.
Swagger is a tool that automatically creates a user-friendly manual for your API based on comments you write in your code. It scans your Go files, finds the descriptions you added, and builds a website where developers can see how to use your API. Think of it like a robot that reads your notes and turns them into a clean instruction manual.