Skip to content

Commit 11560ec

Browse files
committed
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>
1 parent 0750b08 commit 11560ec

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

app.go2go.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
runtime: go116
2+
service: go2goplay
3+
main: ./cmd/redirect
4+
5+
handlers:
6+
- url: /.*
7+
script: auto
8+
9+
env_variables:
10+
PLAY_REDIRECT: "https://gotipplay.golang.org"

cmd/redirect/main.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2021 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// redirect serves an http server that redirects to the URL specified by the
6+
// environment variable PLAY_REDIRECT.
7+
package main
8+
9+
import (
10+
"log"
11+
"net/http"
12+
"os"
13+
)
14+
15+
func main() {
16+
port := os.Getenv("PORT")
17+
if port == "" {
18+
port = "8080"
19+
}
20+
21+
redirect := os.Getenv("PLAY_REDIRECT")
22+
if redirect == "" {
23+
redirect = "https://play.golang.org"
24+
}
25+
26+
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
27+
http.Redirect(w, r, redirect+r.URL.Path, http.StatusFound)
28+
})
29+
30+
log.Printf("Listening on :%v ...", port)
31+
log.Fatalf("Error listening on :%v: %v", port, http.ListenAndServe(":"+port, handler))
32+
}

0 commit comments

Comments
 (0)