playground: format go.mod files; fix paths in formatting errors

Previously, handleFmt applied gofmt/goimports formatting to .go files
only. This change makes it apply formatting to go.mod files as well.
The cmd/go/internal/modfile package (well, a non-internal copy thereof)
is used to perform the go.mod file formatting.

Add test cases for error messages, and fix some cases where the paths
weren't accurate.

Detect when the error was returned by format.Source and needs to be
prefixed by using the fixImports variable instead of checking for the
presence of the prefix. This makes the code simpler and more readable.

Replace old fs.m[f] usage with fs.Data(f) in fmt.go and txtar_test.go.

Updates golang/go#32040
Updates golang/go#31944

Change-Id: Iefef7337f962914817558bcf0c622a952160ac44
Reviewed-on: https://go-review.googlesource.com/c/playground/+/177421
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
4 files changed
tree: f186077564033852cc9784fd23bb19968ec4d405
  1. static/
  2. app.yaml
  3. AUTHORS
  4. cache.go
  5. client.go
  6. codereview.cfg
  7. CONTRIBUTING.md
  8. CONTRIBUTORS
  9. Dockerfile
  10. edit.go
  11. edit.html
  12. enable-fake-time.patch
  13. fake_fs.lst
  14. fmt.go
  15. fmt_test.go
  16. go.mod
  17. go.sum
  18. LICENSE
  19. logger.go
  20. main.go
  21. Makefile
  22. PATENTS
  23. play.go
  24. play_test.go
  25. README.md
  26. sandbox.go
  27. server.go
  28. server_test.go
  29. share.go
  30. store.go
  31. tests.go
  32. txtar.go
  33. txtar_test.go
  34. vet.go
README.md

playground

This subrepository holds the source for the Go playground: https://play.golang.org/

Building

# build the image
docker build -t playground .

Running

docker run --name=play --rm -d -p 8080:8080 playground
# run some Go code
cat /path/to/code.go | go run client.go | curl -s --upload-file - localhost:8080/compile

Deployment

Building the playground Docker container takes more than the default 10 minute time limit of cloud build, so increase its timeout first (note, app/cloud_build_timeout is a global configuration value):

gcloud config set app/cloud_build_timeout 1200  # 20 mins

Alternatively, to avoid Cloud Build and build locally:

make docker
docker tag playground:latest gcr.io/golang-org/playground:latest
docker push gcr.io/golang-org/playground:latest
gcloud --project=golang-org --account=you@google.com app deploy app.yaml --image-url=gcr.io/golang-org/playground:latest

Then:

gcloud --project=golang-org --account=you@google.com app deploy app.yaml

Contributing

To submit changes to this repository, see https://golang.org/doc/contribute.html.