go.tools/cmd/godoc: use go.talks playground package

R=bradfitz
CC=golang-dev
https://golang.org/cl/11416043
This commit is contained in:
Andrew Gerrand 2013-07-17 15:17:04 +10:00
parent 5ff0687cc9
commit 2822addeae
5 changed files with 3 additions and 91 deletions

View File

@ -52,7 +52,6 @@ func init() {
readTemplates()
initHandlers()
registerPublicHandlers(http.DefaultServeMux)
registerPlaygroundHandlers(http.DefaultServeMux)
// initialize default directory tree with corresponding timestamp.
initFSTree()

View File

@ -287,7 +287,6 @@ func main() {
}
registerPublicHandlers(http.DefaultServeMux)
registerPlaygroundHandlers(http.DefaultServeMux)
// Initialize default directory tree with corresponding timestamp.
// (Do it in a goroutine so that launch is quick.)

View File

@ -1,35 +0,0 @@
// Copyright 2012 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.
// App Engine godoc Playground functionality.
// +build appengine
package main
import (
"io"
"net/http"
"appengine"
"appengine/urlfetch"
)
func bounceToPlayground(w http.ResponseWriter, req *http.Request) {
c := appengine.NewContext(req)
client := urlfetch.Client(c)
url := playgroundBaseURL + req.URL.Path
defer req.Body.Close()
resp, err := client.Post(url, req.Header.Get("Content-type"), req.Body)
if err != nil {
http.Error(w, "Internal Server Error", 500)
c.Errorf("making POST request: %v", err)
return
}
defer resp.Body.Close()
if _, err := io.Copy(w, resp.Body); err != nil {
http.Error(w, "Internal Server Error", 500)
c.Errorf("making POST request: %v", err)
}
}

View File

@ -1,41 +0,0 @@
// Copyright 2012 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.
// Stand-alone godoc Playground functionality.
// +build !appengine
package main
import (
"io"
"net/http"
"net/url"
)
var playgroundScheme, playgroundHost string
func init() {
u, err := url.Parse(playgroundBaseURL)
if err != nil {
panic(err)
}
playgroundScheme = u.Scheme
playgroundHost = u.Host
}
// bounceToPlayground forwards the request to play.golang.org.
func bounceToPlayground(w http.ResponseWriter, req *http.Request) {
defer req.Body.Close()
req.URL.Scheme = playgroundScheme
req.URL.Host = playgroundHost
resp, err := http.Post(req.URL.String(), req.Header.Get("Content-type"), req.Body)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
w.WriteHeader(resp.StatusCode)
io.Copy(w, resp.Body)
resp.Body.Close()
}

View File

@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Common Playground functionality.
package main
import (
@ -11,19 +9,11 @@ import (
"fmt"
"go/format"
"net/http"
_ "code.google.com/p/go.talks/pkg/playground"
)
// The server that will service compile and share requests.
const playgroundBaseURL = "http://play.golang.org"
func registerPlaygroundHandlers(mux *http.ServeMux) {
if *showPlayground {
mux.HandleFunc("/compile", bounceToPlayground)
mux.HandleFunc("/share", bounceToPlayground)
} else {
mux.HandleFunc("/compile", disabledHandler)
mux.HandleFunc("/share", disabledHandler)
}
func init() {
http.HandleFunc("/fmt", fmtHandler)
}