go2go: add an app engine service to redirect go2goplay to gotipplay This service will overwrite the existing go2go playground. Updates golang/go#48517 Change-Id: Idc9e6733cc213a2c3e84c71d1c4746dc31feeb62 Reviewed-on: https://go-review.googlesource.com/c/playground/+/364858 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Alexander Rakoczy <alex@golang.org>
diff --git a/app.go2go.yaml b/app.go2go.yaml new file mode 100644 index 0000000..3e70e0e --- /dev/null +++ b/app.go2go.yaml
@@ -0,0 +1,10 @@ +runtime: go116 +service: go2goplay +main: ./cmd/redirect + +handlers: +- url: /.* + script: auto + +env_variables: + PLAY_REDIRECT: "https://gotipplay.golang.org"
diff --git a/cmd/redirect/main.go b/cmd/redirect/main.go new file mode 100644 index 0000000..2292b8e --- /dev/null +++ b/cmd/redirect/main.go
@@ -0,0 +1,32 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// redirect serves an http server that redirects to the URL specified by the +// environment variable PLAY_REDIRECT. +package main + +import ( + "log" + "net/http" + "os" +) + +func main() { + port := os.Getenv("PORT") + if port == "" { + port = "8080" + } + + redirect := os.Getenv("PLAY_REDIRECT") + if redirect == "" { + redirect = "https://play.golang.org" + } + + handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + http.Redirect(w, r, redirect+r.URL.Path, http.StatusFound) + }) + + log.Printf("Listening on :%v ...", port) + log.Fatalf("Error listening on :%v: %v", port, http.ListenAndServe(":"+port, handler)) +}