This site is being rebuilt and some pages are out of date. For current details, write to [email protected]. This notice goes away when the rebuild is done.

No analytics unless you allow it, no tracking. This site keeps in your browser the language you pick, the theme, its colour, which site you chose, the currency on the pricing page and that you closed this notice; signing in adds session cookies. The legal page has the details.

Sign in

Radar · Go · Archive · Week 13 · Mar 23 – 29, 2026

go-proposals-accepted: cmd/doc: add example support

Worth knowingtooling

What changed
The go doc command now accepts a -ex flag that prints examples attached to the API, and it can also print the source of an example function when the symbol name starts with Example.
Production impact
The source does not say.
Try it
Run go doc -ex bytes.Buffer or go doc bytes.ExampleBuffer in a repository that contains example functions.
Source
github.com/golang/go/issues/26715

Understand it, then run it

Run it now

Todaygo
// This program demonstrates that the `-ex` flag for `go doc` is not
// available in Go 1.27.1. It simply prints a message indicating the
// missing feature.

package main

import "fmt"

func main() {
	// In Go 1.27.1, `go doc` does not support the `-ex` flag, so we
	// cannot request examples directly from the command line.
	fmt.Println("The `-ex` flag for `go doc` is not available in Go 1.27.1.")
}

What it printed when we ran it on Go 1.27.1

The `-ex` flag for `go doc` is not available in Go 1.27.1.

Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.

Written by gpt-oss-20b from the linked source · claims checked against the sources · archive, not individually reviewed