Questions tagged [go-playground]

The Go Playground is a web service that runs on golang.org's servers. The service receives a Go program, compiles, links, and runs the program inside a sandbox, then returns the output.

In 2010 a free web service called the Go Playground has been launched which can be used to compile and run any Go code from the browser.

The Go Playground is available at http://play.golang.org/, and it runs on golang.org's servers.

Code on the Go Playground runs in a sandbox environment. Most of the standard library can be used with some exceptions.

The Playground editor page offers some basic features like code formatting (gofmt) including import rewriting, and code sharing (each code gets a unique, sharable link).

The Playground uses output caching: the output of an executed code may be cached so when the same code is executed again, the cached output may be presented without attempting to compile and to run it again. This is important to know when such code is run that should provide random(ized) output. Another important thing is that the time on the playground always begins at 2009-11-10 23:00:00 UTC when a code is executed (to help making it easier to cache programs by giving them deterministic output).

The playground uses the latest stable release of Go. This program shows the precise version.

The official blog post Inside the Go Playground details how the playground is implemented.

33 questions
25
votes
2 answers

Can I import 3rd party package into golang playground

I googled but got no answer. Is it possible? If yes, how to do it? The Go Playground link: https://play.golang.org/
Shuo
  • 8,447
  • 4
  • 30
  • 36
17
votes
3 answers

Package name containing hyphen

I am having some trouble understanding that why my code complains when I have hyphen in package. e.g. if I have a package name foo-bar and I declare that package name package foo-bar foo-bar/config.go:1:13: expected ';', found '-' Then why does…
Aman Chourasiya
  • 1,078
  • 1
  • 10
  • 23
10
votes
3 answers

How do I use the testing package in go playground?

The testing package is available in the go playground. How can I use the go playground to demonstrate testing concepts, without access to go test? My assumption is it's possible using the testing.RunTests function. My attempts to do so always…
Ben Walther
  • 1,605
  • 10
  • 18
8
votes
2 answers

How can I validate a struct datatype with a custom validator?

I am using go-playground/validator/v10 to validate some input and have some trouble with custom validation tags and functions. The problem is that the function is not called when one of the struct fields is a different struct. This is an…
FewWords
  • 595
  • 1
  • 5
  • 22
6
votes
1 answer

How can I define different files or packages inside the Go playground?

How can I define different files or packages inside the Go playground? Specially for checking it can be handy to define a package inside the playground. But to manage this I need to define different files. How can I manage this?
apxp
  • 5,240
  • 4
  • 23
  • 43
6
votes
3 answers

Which packages may be imported in the go playground?

I had trouble finding a list of what packages may be imported in the go playground at http://play.golang.org/. I was trying to use the (apparently experimental) package for ebnf. However even a short program won't import from golang.org (breaks on…
dlamblin
  • 43,965
  • 20
  • 101
  • 140
5
votes
1 answer

Exiting forever loop using channels - issues with Go Playground

I am trying to implement a simple logic where a Producer sends data to a channel ch with an forever for loop and a Consumer reads from the channel ch. The Producer stops producing and exit the forever loop when it receives a signal on the channel…
Picci
  • 16,775
  • 13
  • 70
  • 113
5
votes
0 answers

Why does Go test with blocked channel not reporting deadlock

I met a strange issue when doing test with channels. In a normal main function, the following code will report the deadlock error. package main import ( "fmt" ) func main() { c := make(chan int) c <- 1 fmt.Println(<-c) } But on…
user163947
4
votes
1 answer

Closing stop channel does not stop goroutines

INTRODUCTION: I am just starting to learn the Go language and have reached the lesson about concurrency. I have invented a small task for myself to try to implement what I have learned about closing goroutines. PROBLEM: If we close channel it's case…
AlwaysLearningNewStuff
  • 2,939
  • 3
  • 31
  • 84
4
votes
2 answers

go2go.playground - expected type, found 'type' (and 1 more errors)

I try to run examples from the design draft (The Next Step for Generics) on go2go.playground type Pair(type T) struct { f1, f2 T } , but get an error prog.go2:14:11: expected type, found 'type' (and 1 more errors) Where can I find actual go…
kozmo
  • 4,024
  • 3
  • 30
  • 48
3
votes
2 answers

How can I import a library from github to GO playground?

Hi I want to import a 3rd party library to GO playground, I saw an answer for this question: https://stackoverflow.com/a/27813778/6638204 but it said that this can not be done, but the xiam/go-playground library on github states that it can do this.…
Said Saifi
  • 1,995
  • 7
  • 26
  • 45
3
votes
2 answers

Discrepancies between Go Playground and Go on my machine?

To settle some misunderstandings I have about goroutines, I went to the Go playground and ran this code: package main import ( "fmt" ) func other(done chan bool) { done <- true go func() { for { fmt.Println("Here") …
user3835277
2
votes
2 answers

Accessing validation tag parameters of other fields in go-playground/validator

I'm using the go-playground/validator package to validate a struct in Go. Here is my struct definition: GetLogRequest struct { CreatedAtMin string `query:"created_at_min" validate:"omitempty,datetime=2006-01-02"` CreatedAtMax …
2
votes
0 answers

Why doesn’t 'dive' work on gin? (about validator)

I just would like to do like the below about validation on Gin(Golang). type Accounts struct { Accounts []*Account `json:"accounts" binding:"required,dive"` } type Account struct { BusinessId string `json:"business_id"…
TomoEno
  • 21
  • 1
2
votes
2 answers

How to validate allowed fields in json body in go validation

I have a go struct which I'm using for my POST of an entity type Student struct { ID string `json:"id" firestore:"id"` Name string `json:"name" validate:"required" firestore:"name"` } From the POST body request I can…
1
2 3