Home
Tutorials

Go / godoc Docs

Generate Go API reference from package comments, exported symbols, and examples.

Sourcey can render Go package documentation directly from Go source. Use a godoc tab when your project has package comments, exported functions, types, methods, fields, constants, variables, or examples that should live beside your guides and API docs.

The live reference is the Scafld Go API: 0state.com/scafld/docs/go-api.

When to use it

Use native godoc support when:

  • your Go API reference currently only lives on pkg.go.dev;
  • you want package docs inside your own documentation site;
  • you want Go symbols included in Sourcey search, llms.txt, and llms-full.txt;
  • you need guides, changelog, OpenAPI, MCP, Doxygen, and Go reference in one static site.

Do not route Go through Doxygen. Go source, doc comments, examples, module metadata, and the Go toolchain are the source of truth.

Configure a Go API tab

import { defineConfig, godoc, markdown } from "sourcey";

export default defineConfig({
  name: "My Go Project",
  navigation: {
    tabs: [
      {
        tab: "Documentation",
        slug: "",
        source: markdown({
          groups: [
            { group: "Getting Started", pages: ["introduction", "quickstart"] },
          ],
        }),
      },
      {
        tab: "Go API",
        slug: "go-api",
        source: godoc({
          module: ".",
          packages: ["./..."],
          includeTests: true,
        }),
      },
    ],
  },
});

module points at the Go module root. packages uses the same pattern shape as go list, so ./... includes every package below the module root.

String shorthand

For the common case, pass the module path directly:

{
  tab: "Go API",
  source: godoc("."),
}

This expands to a live build over ./... with examples enabled.

Snapshot mode

If the docs build host does not have Go installed, generate a portable snapshot and commit it:

npx sourcey godoc --module . --packages './...' --out docs/godoc.json

Then configure Sourcey to read the snapshot:

{
  tab: "Go API",
  slug: "go-api",
  source: godoc({
    snapshot: "./godoc.json",
    mode: "snapshot",
  }),
}

Snapshot mode is useful for static docs hosts, hermetic CI jobs, and repos that want deterministic docs output across machines.

Standalone Go CLI

Go-only teams can use sourcey-godoc without installing Node:

go install github.com/sourcey/sourcey/go/sourcey-godoc/cmd/sourcey-godoc@latest
sourcey-godoc generate --out site

The standalone CLI is the small Go-first path. The full Sourcey site is the path when you want Go reference beside guides, specs, changelog, examples, and agent-readable output.

Output

Sourcey renders:

  • one module overview page;
  • one page per selected package;
  • package docs from // Package ... comments;
  • exported constants, variables, functions, types, methods, and fields;
  • examples from _test.go files when includeTests is enabled;
  • stable symbol anchors;
  • entries in search, sitemap, llms.txt, and llms-full.txt.

The result is still static HTML. No runtime service is required.