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
2
votes
1 answer

golang pic.ShowImage why is it not generating the image but sending me the base64 value

i use golang study golang, Is there something wrong with my goland? Need to change configuration information? my code package main import ( "golang.org/x/tour/pic" "image" "image/color" ) type Image struct{} //新建一个Image结构体 func (i…
xin.chen
  • 964
  • 2
  • 8
  • 24
2
votes
0 answers

How to perform the parameter type check in golang gin using validator?

I have a Validator struct like this type UploadFileFormValidator struct { File []*multipart.FileHeader `form:"File" binding:"required,min=1"` InputKey string `form:"Key" binding:"disallowed-char"` Permission…
JY F
  • 39
  • 1
  • 6
2
votes
1 answer

Will the code be deleted when I close vscode-go:playground?

I accidentally clicked on "go run on go playground" when I was developing in vscode. Since it is a company code, I would like to know if the code will be deleted.
2
votes
1 answer

validating array of structs using goplayground validator library

How can I validate a slice of structs using validator framework? For example, in the following type definitions, I want to validate each element in the field Puppies. type User struct { FirstName string `json:"fname" validate:"alpha"` …
Rajesh
  • 61
  • 1
  • 2
  • 5
1
vote
1 answer

How can I validate an array of strings from a JSON in Golang with validator package?

I'm using the package validator to help me deal with JSON fields in golang. I know how to use oneof to check for specific values in a field. Is there any option for doing the same, but for an array of strings? I'm trying to do something like…
Hugo-Cruz
  • 88
  • 1
  • 8
1
vote
1 answer

How to import specific version of 3rd party library in Go Playground?

Let's say I want to import version v0.11.0 of Slack Go package. In CLI I would call: go get github.com/slack-go/slack@v0.11.0 but in Go Playground I can only use import. I've tried import "github.com/slack-go/slack@v0.11.0" but that didn't work. How…
gondo
  • 979
  • 1
  • 10
  • 29
1
vote
1 answer

Need to validate two fields in go-playground/validator/v10

need to check atleast one of field should be present email, phone atleast one is mandatory currently I have custom validator func validateEmailPhone(fl validator.FieldLevel) bool { user := fl.Top().Interface().(models.User) validate :=…
Arul Ranjith
  • 465
  • 1
  • 5
  • 17
1
vote
0 answers

Socket Hang up : Couldn't get response | While using validator to validate JSON data in Go gin using go-playground/validator

return func(c *gin.Context) { var user models.User err := c.BindJSON(&user) if err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } validation_err :=…
1
vote
2 answers

Backspace character does not work in the Go playground

I am new to Go. Just learnt the various uses of fmt.Println(). I tried the following stuff in the official playground but got a pretty unexpected output. Please explain where I have gone wrong in my understanding. input: fmt.Println("hi\b",…
justanotherguy
  • 399
  • 5
  • 16
1
vote
1 answer

cmd.StdoutPipe example in go pkg docs does not run in playground

cmd.StdoutPipe example at go documentation: https://pkg.go.dev/os/exec#example-Cmd.StdoutPipe does not run in playground. https://play.golang.org/p/ek7-_Xa_bN3 Error: fatal error: all goroutines are asleep - deadlock! goroutine 1 [IO…
1
vote
1 answer

playground - timeout running go build

When I try to run code snippet on playground (snippet) , I get an error: timeout running go build go: finding module for package github.com/spf13/viper go: downloading github.com/spf13/viper v1.7.1 go: found github.com/spf13/viper in…
kozmo
  • 4,024
  • 3
  • 30
  • 48
0
votes
0 answers

go playground validaor failing with special character hex code

trying to exclude special characters in go playground validator, using hexcode representation struct A{ ID string `json:"id" validate:"excludesall=0x3D"` } validator behaving unexpectedly, it fails when ID: "123", "12D" but won't fail when ID:…
MrE
  • 11
  • 4
0
votes
1 answer

Go playground url validate

I am sending a request which has a URL and Content in the body. The validations are such that either URL or epicentre is mandatory. The program is erroring when the URL is empty as url validate on an empty string is failing. Is there a way to run…
Daffodil
  • 69
  • 6
0
votes
1 answer

net/http doesn't work in the Go Playground

Can someone please explain what am I doing wrong. So basically I'am trying to make a simple HTTP GET request. I copied code from https://gobyexample.com/http-clients. When I'm running it locally everything works fine, but in go playground…
Vor
  • 33,215
  • 43
  • 135
  • 193
0
votes
1 answer

How to chain validations together using Golang go-playground/validator?

I am using https://github.com/go-playground/validator for a REST API server. I am using the same struct for different endpoint with different validation requirement. For example, /users/login requires only email and password. However, to create a…
huggie
  • 17,587
  • 27
  • 82
  • 139