-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathplay-local.go
41 lines (34 loc) · 918 Bytes
/
play-local.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// 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()
}