Copyright 2020 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 frontend

import (
	
	
	
	
	
	

	
)
playgroundURL is the playground endpoint used for share links.
var playgroundURL = &url.URL{Scheme: "https", Host: "play.golang.org"}

func ( http.ResponseWriter,  int) {
	http.Error(, http.StatusText(), )
}
proxyPlayground is a handler that proxies playground requests to play.golang.org.
makePlaygroundProxy creates a proxy that sends requests to play.golang.org. The prefix /play is removed from the URL path.
func ( *url.URL) *httputil.ReverseProxy {
	return &httputil.ReverseProxy{
		Director: func( *http.Request) {
			.Header.Add("X-Forwarded-Host", .Host)
			.Header.Add("X-Origin-Host", .Host)
			.Host = .Host
			.URL.Scheme = .Scheme
			.URL.Host = .Host
			.URL.Path = strings.TrimPrefix(.URL.Path, "/play")
		},
		ErrorHandler: func( http.ResponseWriter,  *http.Request,  error) {
			log.Errorf(.Context(), "ERROR playground proxy error: %v", )
			httpErrorStatus(, http.StatusInternalServerError)
		},
	}
}

type fmtResponse struct {
	Body  string
	Error string
}
fmtHandler takes a Go program in its "body" form value, formats it with standard gofmt formatting, and writes a fmtResponse as a JSON object.
func ( *Server) ( http.ResponseWriter,  *http.Request) {
	 := new(fmtResponse)
	,  := format.Source([]byte(.FormValue("body")))
	if  != nil {
		.Error = .Error()
	} else {
		.Body = string()
	}
	.Header().Set("Content-type", "application/json; charset=utf-8")
	json.NewEncoder().Encode()