x1unix / go-playground

Better Go Playground powered by Monaco editor
https://goplay.tools/
MIT License
1.3k stars 82 forks source link

Support `//go:generate` #353

Open lesiw opened 4 months ago

lesiw commented 4 months ago

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
github-actions[bot] commented 3 months ago

This issue is stale because it has been open for 15 days with no activity. It will be closed if no further activity occurs. Thank you.

x1unix commented 3 months ago

So at the moment, Playground offers two modes:

Regarding first mode - I suggest creating an issue in go's repo.

Regarding WASM - there is a plan to move Go compiler into a browser. This will resolve potential security concerns but still go:generate support will be limited to only running other Go packages.