Documentation
¶
Index ¶
- Constants
- type Backend
- type Client
- func (cli *Client) Download(w io.Writer, hashOrURL string) error
- func (cli *Client) Format(src interface{}, imports bool) (*FormatResult, error)
- func (cli *Client) Run(src interface{}) (*RunResult, error)
- func (cli *Client) Share(src interface{}) (*url.URL, error)
- func (cli *Client) Version() (*VersionResult, error)
- type FormatResult
- type HTTPClient
- type HTTPClientFunc
- type RunEvent
- type RunResult
- type VersionResult
Constants ¶
const ( // FrontBaseURL is frontend of the Go Playground. FrontBaseURL = "https://go.dev/play" // BaseURL is the default base URL of the Go Playground. BaseURL = "https://play.golang.org" // Deprecated: Go2GoBaseURL is the base URL of go2goplay.golang.org. Go2GoBaseURL = "https://go2goplay.golang.org" // Version is version of using Go Playground. Version = "2" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶ added in v0.3.0
type Backend string
Backend indicates run Go environment.
type Client ¶
type Client struct {
FrontBaseURL string
BaseURL string
Backend Backend
HTTPClient HTTPClient
}
Client is a client of Go Playground. If BaseURL is empty, Client uses default BaseURL. HTTPClient can be set instead of http.DefaultClient.
func (*Client) Download ¶
Download downloads source code hosted on Playground. The source would be written into w.
func (*Client) Format ¶
func (cli *Client) Format(src interface{}, imports bool) (*FormatResult, error)
Format formats the given src by gofmt or goimports. src can be set string, []byte and io.Reader value. If imports is true, Format formats and imports unimport packages with goimports.
func (*Client) Run ¶
Run compiles and runs the given src. src can be set string, []byte and io.Reader value.
func (*Client) Share ¶
Share generates share URL of the given src. src can be set string, []byte and io.Reader value.
func (*Client) Version ¶ added in v0.3.0
func (cli *Client) Version() (*VersionResult, error)
Version gets version and release tags which is used in the Go Playground.
type FormatResult ¶
type FormatResult struct {
// Body is the formatted source code.
Body string
// Error is a gofmt error.
Error string
}
FormatResult is result of Client.Format.
type HTTPClient ¶
type HTTPClient interface {
// Do method send a HTTP request.
Do(*http.Request) (*http.Response, error)
}
HTTPClient is an interface of minimum HTTP client. net/http.Client implements this interface.
type HTTPClientFunc ¶
HTTPClientFunc implements HTTPClient.
type RunEvent ¶
type RunEvent struct {
// Message is a message which is outputed to stdout or stderr.
Message string
// Kind has stdout or stderr value.
Kind string
// Delay represents delay time to print the message to stdout or stderr.
Delay time.Duration
}
RunEvent represents output events to stdout or stderr of Client.Run.
type RunResult ¶
type RunResult struct {
// Errors is compile or runtime error on Go Playground.
Errors string
// Events has output events on Go Playground.
Events []*RunEvent
}
RunResult is result of Client.Run.
type VersionResult ¶ added in v0.3.0
VersionResult is result of Client.Format.