зеркало из https://github.com/golang/tools.git
playground: recognize managed vm's as being "on app engine"
Change-Id: I117b113e2782cab1180e6f56e1869525564ab18f Reviewed-on: https://go-review.googlesource.com/14663 Reviewed-by: Andrew Gerrand <adg@golang.org>
This commit is contained in:
Родитель
25693e10e1
Коммит
ffb6076c75
|
@ -14,17 +14,11 @@ import (
|
|||
_ "golang.org/x/tools/playground"
|
||||
)
|
||||
|
||||
var basePath = "./present/"
|
||||
|
||||
func init() {
|
||||
initTemplates(basePath)
|
||||
playScript(basePath, "HTTPTransport")
|
||||
initTemplates("./present/")
|
||||
present.PlayEnabled = true
|
||||
initPlayground("./present/", nil)
|
||||
|
||||
// App Engine has no /etc/mime.types
|
||||
mime.AddExtensionType(".svg", "image/svg+xml")
|
||||
}
|
||||
|
||||
func playable(c present.Code) bool {
|
||||
return present.PlayEnabled && c.Play && c.Ext == ".go"
|
||||
}
|
||||
|
|
|
@ -15,35 +15,34 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/tools/playground/socket"
|
||||
"golang.org/x/tools/present"
|
||||
)
|
||||
|
||||
const basePkg = "golang.org/x/tools/cmd/present"
|
||||
|
||||
var basePath string
|
||||
var (
|
||||
httpAddr = flag.String("http", "127.0.0.1:3999", "HTTP service address (e.g., '127.0.0.1:3999')")
|
||||
originHost = flag.String("orighost", "", "host component of web origin URL (e.g., 'localhost')")
|
||||
basePath = flag.String("base", "", "base path for slide template and static resources")
|
||||
nativeClient = flag.Bool("nacl", false, "use Native Client environment playground (prevents non-Go code execution)")
|
||||
)
|
||||
|
||||
func main() {
|
||||
httpAddr := flag.String("http", "127.0.0.1:3999", "HTTP service address (e.g., '127.0.0.1:3999')")
|
||||
originHost := flag.String("orighost", "", "host component of web origin URL (e.g., 'localhost')")
|
||||
flag.StringVar(&basePath, "base", "", "base path for slide template and static resources")
|
||||
flag.BoolVar(&present.PlayEnabled, "play", true, "enable playground (permit execution of arbitrary user code)")
|
||||
nativeClient := flag.Bool("nacl", false, "use Native Client environment playground (prevents non-Go code execution)")
|
||||
flag.Parse()
|
||||
|
||||
if basePath == "" {
|
||||
if *basePath == "" {
|
||||
p, err := build.Default.Import(basePkg, "", build.FindOnly)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Couldn't find gopresent files: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, basePathMessage, basePkg)
|
||||
os.Exit(1)
|
||||
}
|
||||
basePath = p.Dir
|
||||
*basePath = p.Dir
|
||||
}
|
||||
err := initTemplates(basePath)
|
||||
err := initTemplates(*basePath)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to parse templates: %v", err)
|
||||
}
|
||||
|
@ -58,6 +57,7 @@ func main() {
|
|||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
origin := &url.URL{Scheme: "http"}
|
||||
if *originHost != "" {
|
||||
origin.Host = net.JoinHostPort(*originHost, port)
|
||||
|
@ -76,20 +76,8 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
if present.PlayEnabled {
|
||||
if *nativeClient {
|
||||
socket.RunScripts = false
|
||||
socket.Environ = func() []string {
|
||||
if runtime.GOARCH == "amd64" {
|
||||
return environ("GOOS=nacl", "GOARCH=amd64p32")
|
||||
}
|
||||
return environ("GOOS=nacl")
|
||||
}
|
||||
}
|
||||
playScript(basePath, "SocketTransport")
|
||||
http.Handle("/socket", socket.NewHandler(origin))
|
||||
}
|
||||
http.Handle("/static/", http.FileServer(http.Dir(basePath)))
|
||||
initPlayground(*basePath, origin)
|
||||
http.Handle("/static/", http.FileServer(http.Dir(*basePath)))
|
||||
|
||||
if !ln.Addr().(*net.TCPAddr).IP.IsLoopback() &&
|
||||
present.PlayEnabled && !*nativeClient {
|
||||
|
@ -100,10 +88,6 @@ func main() {
|
|||
log.Fatal(http.Serve(ln, nil))
|
||||
}
|
||||
|
||||
func playable(c present.Code) bool {
|
||||
return present.PlayEnabled && c.Play
|
||||
}
|
||||
|
||||
func environ(vars ...string) []string {
|
||||
env := os.Environ()
|
||||
for _, r := range vars {
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright 2015 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.
|
||||
|
||||
// +build appengine appenginevm
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
|
||||
"golang.org/x/tools/present"
|
||||
)
|
||||
|
||||
func initPlayground(basepath string, origin *url.URL) {
|
||||
playScript(basepath, "HTTPTransport")
|
||||
}
|
||||
|
||||
func playable(c present.Code) bool {
|
||||
return present.PlayEnabled && c.Play && c.Ext == ".go"
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
// Copyright 2015 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.
|
||||
|
||||
// +build !appengine,!appenginevm
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"runtime"
|
||||
|
||||
"golang.org/x/tools/playground/socket"
|
||||
"golang.org/x/tools/present"
|
||||
)
|
||||
|
||||
func initPlayground(basepath string, origin *url.URL) {
|
||||
if present.PlayEnabled {
|
||||
if *nativeClient {
|
||||
socket.RunScripts = false
|
||||
socket.Environ = func() []string {
|
||||
if runtime.GOARCH == "amd64" {
|
||||
return environ("GOOS=nacl", "GOARCH=amd64p32")
|
||||
}
|
||||
return environ("GOOS=nacl")
|
||||
}
|
||||
}
|
||||
playScript(basepath, "SocketTransport")
|
||||
http.Handle("/socket", socket.NewHandler(origin))
|
||||
}
|
||||
}
|
||||
|
||||
func playable(c present.Code) bool {
|
||||
return present.PlayEnabled && c.Play
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
// Copyright 2015 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.
|
||||
|
||||
// +build appenginevm
|
||||
|
||||
package playground
|
||||
|
||||
func init() {
|
||||
onAppengine = true
|
||||
}
|
|
@ -49,7 +49,7 @@ func passThru(w io.Writer, req *http.Request) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
var onAppengine = false // will be overriden by appengine.go
|
||||
var onAppengine = false // will be overriden by appengine.go and appenginevm.go
|
||||
|
||||
func allowShare(r *http.Request) bool {
|
||||
if !onAppengine {
|
||||
|
|
Загрузка…
Ссылка в новой задаче