
How I Used go/ast to Auto-Generate API Docs from Go HTTP Handlers
Most Go API documentation tools require you to litter your code with annotations. I wanted to see how far static analysis could go — extracting routes, parameters, request/response types, and even auth patterns purely from the AST. Turns out, pretty far. This is the story of building GoDoc Live , an open-source CLI that reads your Go HTTP handlers and generates interactive documentation without touching your code. The Problem If you've used swaggo, you know the drill: dozens of comment annotations above every handler. They drift out of sync with the actual code. You end up maintaining two sources of truth. I wanted a tool where the Go source code IS the documentation. Point it at your project, get docs. The Architecture The analysis pipeline has 8 stages: Stage 1-2: Load & Detect Everything starts with go/packages in LoadAllSyntax mode. This gives us both the full AST and type information for every package. Then we walk import declarations to detect whether the project uses chi, gin, o
Continue reading on Dev.to Tutorial
Opens in a new tab




