Documentation
¶
Overview ¶
Package goplay provides The Go Playground (https://play.golang.org/) client
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultClient = &Client{}
DefaultClient is default Go Playground client.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { // The base URL of The Go Playground. Default is `https://play.golang.org/`. BaseURL string // The HTTP client to use when sending requests. Defaults to // `http.DefaultClient`. HTTPClient *http.Client }
Client represensts The Go Playground client.
func (*Client) Compile ¶
Compile compiles code on The Go Playground.
Example ¶
code := ` package main import ( "fmt" "time" ) func main() { for i := 3; i > 0; i-- { fmt.Printf("%d...\n", i) time.Sleep(1 * time.Second) } fmt.Println("GO!") } ` // You can use `DefaultClient` instead of creating `Client` if you want cli := &Client{HTTPClient: mockCompileClient} resp, err := cli.Compile(strings.NewReader(code)) if err != nil { log.Fatal(err) } for _, e := range resp.Events { // do not emulate delay. // time.Sleep(e.Delay) fmt.Print(e.Message) }
Output: 3... 2... 1... GO!
func (*Client) Run ¶
Run runs code which compiled in The Go Playground.
Example ¶
code := ` package main import "fmt" func main() { fmt.Println("Hello, 世界!") } ` // You can use `DefaultClient` instead of creating `Client` if you want cli := &Client{HTTPClient: mockRunClient} if err := cli.Run(strings.NewReader(code), os.Stdout, os.Stderr); err != nil { log.Fatal(err) }
Output: Hello, 世界!
Click to show internal directories.
Click to hide internal directories.