How to Use the Go Playground Effectively

Cli
Write self-contained example functions in _test.go files with no parameters to run them in the Go Playground.

Use the Go Playground by writing self-contained example functions in _test.go files that the doc.Examples function can extract and run. Ensure your package name ends in _test and your example function has no parameters or return values to make it playable.

package mypkg_test

import "fmt"

// ExampleHello demonstrates the Hello function.
func ExampleHello() {
	fmt.Println(Hello())
	// Output: Hello, World!
}

func Hello() string {
	return "Hello, World!"
}