Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var (
ConfigDefault = NewConfig("https://go.dev", "_/share", "play/p") // A configuration representing default values for the current Go Playground.
)
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents an HTTP and Config instance combo used to make calls to the Go Playground.
func NewClient ¶
NewClient returns a new instance of struct Client using the specified Config instance.
func (Client) Fetch ¶
Fetch takes a single slice of bytes representing a snippet of Go source code to process in the Go Playground. This method returns either an error or a shareable Go Playground URL.
Example (File) ¶
client := play.NewClient(play.ConfigDefault) code, err := os.ReadFile("play.go") if err != nil { log.Fatal(err) } share, err := client.Fetch(code) if err != nil { log.Fatal(err) } pattern := regexp.MustCompile(playUrlPattern) fmt.Println(pattern.FindStringIndex(share) != nil)
Output: true
Example (String) ¶
code := []byte(`package main import "fmt" func main() { fmt.Println("Hello world!") }`) client := play.NewClient(play.ConfigDefault) share, err := client.Fetch(code) if err != nil { log.Fatal(err) } pattern := regexp.MustCompile(playUrlPattern) fmt.Println(pattern.FindStringIndex(share) != nil)
Output: true
func (Client) FetchGroup ¶
FetchGroup takes a slice of byte slices representing multiple snippets of Go source code to process. This method makes use of the `errgroup` package which utilises Goroutines to process multiple snippets concurrently. This method stops on the first non-nil error response. The order of resulting slice of strings is not guaranteed.
Example (File) ¶
var ( bytes [][]byte files = []string{"play_test.go", "config_test.go"} client = play.NewClient(play.ConfigDefault) ) for _, file := range files { code, err := os.ReadFile(file) if err != nil { log.Fatal(err) } bytes = append(bytes, code) } shares, err := client.FetchGroup(bytes) if err != nil { log.Fatal(err) } pattern := regexp.MustCompile(playUrlPattern) for _, share := range shares { fmt.Println(pattern.FindStringIndex(share) != nil) }
Output: true true
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config exposes URL patterns used to interact with various versions of the Go Playground.
func NewConfig ¶
NewConfig returns a new instance of struct Config using the specified portions of the target Go Playground endpoints.
func (Config) GetPostUrl ¶
GetPostUrl returns a formatted string representing the full submission URL.
func (Config) GetShareUrl ¶
GetShareUrl returns a formatted string representing the shareable play URL.