How swaggo/echo-swagger works
Project type and purpose
• It’s a Go “middleware library” (not a standalone full-stack app) for the Echo web framework.
• Purpose: at build time it uses the Swag CLI to parse Go source comments and generate docs (Go files + JSON/YAML). At runtime it mounts an HTTP handler (/swagger/*) that serves the generated Swagger UI and spec.
File structure
Top-level:
• swagger.go & swagger_test.go – core middleware implementation and tests
• go.mod/go.sum – Go modules
• example/v2 & example/v3 – sample Echo apps (OAS2 & OAS3) each containing:
– main.go (imports echo-swagger and generated docs)
– docs/ (auto-generated by swag init)
• CI config, GitHub workflows, release tooling (goreleaser), templates, etc.
README for additional insights
• Dependencies: github.com/swaggo/swag/cmd/swag (“Swag CLI”), Echo v4, echo-swagger itself.
• Workflow:
a) Developer annotates API in Go with special comments.
b) Runs swag init → produces docs/ folder (doc.go, swagger.json, .yaml).
c) Imports github.com/swaggo/echo-swagger.
d) In Echo app: e.GET("/swagger/*", echoSwagger.WrapHandler) (or WrapHandlerV3).
e) Client browses to /swagger/index.html.