Skip to content

Support //go:generate #353

@lesiw

Description

@lesiw

One of the limitations of the original Go Playground is that //go:generate directives are not evaluated before program execution. It might be useful to have a playground that permits experimentation with generated code.

Here's an example of a program using the stringer package, as demonstrated in the original blog post announcing go:generate.

package main

import "fmt"

//go:generate go run golang.org/x/tools/cmd/stringer@latest -type=Pill
type Pill int

const (
	Placebo Pill = iota
	Aspirin
	Ibuprofen
	Paracetamol
	Acetaminophen = Paracetamol
)

func main() {
	fmt.Println(Aspirin.String())
}
$ go generate && go build -o main && ./main
Aspirin

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions