mirror of
https://github.com/golang/go
synced 2024-11-05 15:46:11 -07:00
5ebbcd132f
Rewrite performed with this command: sed -i '' 's_code.google.com/p/go\._golang.org/x/_g' \ $(grep -lr 'code.google.com/p/go.' *) LGTM=rsc R=rsc CC=golang-codereviews https://golang.org/cl/170920043
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
// 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.
|
|
|
|
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"path/filepath"
|
|
"time"
|
|
|
|
"golang.org/x/tools/godoc/static"
|
|
)
|
|
|
|
var scripts = []string{"jquery.js", "jquery-ui.js", "playground.js", "play.js"}
|
|
|
|
// playScript registers an HTTP handler at /play.js that serves all the
|
|
// scripts specified by the variable above, and appends a line that
|
|
// initializes the playground with the specified transport.
|
|
func playScript(root, transport string) {
|
|
modTime := time.Now()
|
|
var buf bytes.Buffer
|
|
for _, p := range scripts {
|
|
if s, ok := static.Files[p]; ok {
|
|
buf.WriteString(s)
|
|
continue
|
|
}
|
|
b, err := ioutil.ReadFile(filepath.Join(root, "static", p))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
buf.Write(b)
|
|
}
|
|
fmt.Fprintf(&buf, "\ninitPlayground(new %v());\n", transport)
|
|
b := buf.Bytes()
|
|
http.HandleFunc("/play.js", func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-type", "application/javascript")
|
|
http.ServeContent(w, r, "", modTime, bytes.NewReader(b))
|
|
})
|
|
}
|