Documentation
¶
Index ¶
- Constants
- Variables
- func NewFileServerWithStatus(name string, code int) http.HandlerFunc
- func ServeFileWithStatus(rw http.ResponseWriter, r *http.Request, name string, code int)
- func WrapHandler(h HandlerFunc, guards ...GuardFn) http.HandlerFunc
- func WriteJSON(w http.ResponseWriter, i interface{})
- type APIv1Handler
- func (s *APIv1Handler) HandleArtifactRequest(w http.ResponseWriter, r *http.Request) error
- func (s *APIv1Handler) HandleGetSnippet(w http.ResponseWriter, r *http.Request) error
- func (s *APIv1Handler) HandleGetSuggestion(w http.ResponseWriter, r *http.Request) error
- func (s *APIv1Handler) HandleGetVersion(w http.ResponseWriter, _ *http.Request) error
- func (s *APIv1Handler) HandleGetVersions(w http.ResponseWriter, r *http.Request) error
- func (s *APIv1Handler) HandleShare(w http.ResponseWriter, r *http.Request) error
- func (s *APIv1Handler) Mount(r *mux.Router)
- type APIv2Handler
- func (h *APIv2Handler) HandleCompile(w http.ResponseWriter, r *http.Request) error
- func (h *APIv2Handler) HandleFormat(w http.ResponseWriter, r *http.Request) error
- func (h *APIv2Handler) HandleGetSnippet(w http.ResponseWriter, r *http.Request) error
- func (h *APIv2Handler) HandleRun(w http.ResponseWriter, r *http.Request) error
- func (h *APIv2Handler) HandleShare(w http.ResponseWriter, r *http.Request) error
- func (h *APIv2Handler) Mount(r *mux.Router)
- type APIv2HandlerConfig
- type BackendVersionProvider
- type BackendVersionService
- type BuildResponseV1
- type BuildResponseV2
- type DeprecatedHeader
- type ErrorResponse
- type FilesPayload
- type GuardFn
- type HTTPError
- type HandlerFunc
- type PlaygroundVersions
- type RunParams
- type RunResponse
- type ServiceConfig
- type ShareResponse
- type SnippetResponse
- type SpaFileServer
- type SuggestionRequest
- type SuggestionsResponse
- type TemplateArguments
- type TemplateFileServer
- type VersionResponse
- type VersionsInformation
Constants ¶
const ( IndexFileName = "index.html" NotFoundFileName = "404.html" )
const (
VersionCacheTTL = 24 * time.Hour
)
Variables ¶
var ErrEmptyRequest = errors.New("empty request")
var ErrSnippetTooLarge = Errorf( http.StatusRequestEntityTooLarge, "code snippet too large (max %d bytes)", goplay.MaxSnippetSize, )
ErrSnippetTooLarge is snippet max size limit error
Functions ¶
func NewFileServerWithStatus ¶
func NewFileServerWithStatus(name string, code int) http.HandlerFunc
NewFileServerWithStatus returns http.Handler which serves specified file with desired HTTP status
func ServeFileWithStatus ¶
ServeFileWithStatus serves file in HTTP response with specified HTTP status.
func WrapHandler ¶
func WrapHandler(h HandlerFunc, guards ...GuardFn) http.HandlerFunc
WrapHandler wraps handler
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, i interface{})
WriteJSON encodes object as JSON and writes it to stdout
Types ¶
type APIv1Handler ¶
type APIv1Handler struct {
// contains filtered or unexported fields
}
APIv1Handler is API v1 handler
func NewAPIv1Handler ¶
func NewAPIv1Handler(cfg ServiceConfig, client *goplay.Client, builder builder.BuildService) *APIv1Handler
NewAPIv1Handler is APIv1Handler constructor
func (*APIv1Handler) HandleArtifactRequest ¶
func (s *APIv1Handler) HandleArtifactRequest(w http.ResponseWriter, r *http.Request) error
HandleArtifactRequest handles WASM build artifact request
func (*APIv1Handler) HandleGetSnippet ¶
func (s *APIv1Handler) HandleGetSnippet(w http.ResponseWriter, r *http.Request) error
HandleGetSnippet handles snippet load
func (*APIv1Handler) HandleGetSuggestion ¶
func (s *APIv1Handler) HandleGetSuggestion(w http.ResponseWriter, r *http.Request) error
HandleGetSuggestion handles code suggestion
func (*APIv1Handler) HandleGetVersion ¶
func (s *APIv1Handler) HandleGetVersion(w http.ResponseWriter, _ *http.Request) error
HandleGetVersion handles /api/version
func (*APIv1Handler) HandleGetVersions ¶
func (s *APIv1Handler) HandleGetVersions(w http.ResponseWriter, r *http.Request) error
func (*APIv1Handler) HandleShare ¶
func (s *APIv1Handler) HandleShare(w http.ResponseWriter, r *http.Request) error
HandleShare handles snippet share
func (*APIv1Handler) Mount ¶
func (s *APIv1Handler) Mount(r *mux.Router)
Mount mounts service on route
type APIv2Handler ¶
type APIv2Handler struct {
// contains filtered or unexported fields
}
func NewAPIv2Handler ¶
func NewAPIv2Handler(cfg APIv2HandlerConfig) *APIv2Handler
func (*APIv2Handler) HandleCompile ¶
func (h *APIv2Handler) HandleCompile(w http.ResponseWriter, r *http.Request) error
HandleCompile handles WebAssembly compile requests.
func (*APIv2Handler) HandleFormat ¶
func (h *APIv2Handler) HandleFormat(w http.ResponseWriter, r *http.Request) error
HandleFormat handles gofmt requests.
func (*APIv2Handler) HandleGetSnippet ¶
func (h *APIv2Handler) HandleGetSnippet(w http.ResponseWriter, r *http.Request) error
HandleGetSnippet handles requests to get snippet by id.
func (*APIv2Handler) HandleRun ¶
func (h *APIv2Handler) HandleRun(w http.ResponseWriter, r *http.Request) error
func (*APIv2Handler) HandleShare ¶
func (h *APIv2Handler) HandleShare(w http.ResponseWriter, r *http.Request) error
HandleShare handles snippet share requests.
func (*APIv2Handler) Mount ¶
func (h *APIv2Handler) Mount(r *mux.Router)
type APIv2HandlerConfig ¶
type BackendVersionProvider ¶
type BackendVersionProvider interface {
GetVersions(ctx context.Context) (*VersionsInformation, error)
}
type BackendVersionService ¶
type BackendVersionService struct {
// contains filtered or unexported fields
}
BackendVersionService provides information about used Go versions for all backends.
func (*BackendVersionService) GetVersions ¶
func (svc *BackendVersionService) GetVersions(ctx context.Context) (*VersionsInformation, error)
GetVersions provides Go version information for all backends.
type BuildResponseV1 ¶
type BuildResponseV1 struct { DeprecatedHeader // Formatted contains goimport'ed code. Formatted string `json:"formatted,omitempty"` // FileName is file name FileName string `json:"fileName,omitempty"` }
BuildResponseV1 is build response for legacy API.
type BuildResponseV2 ¶
type BuildResponseV2 struct { // FileName is file name FileName string `json:"fileName,omitempty"` // IsUnitTest indicates whether payload is a Go test. IsTest bool `json:"isTest,omitempty"` // HasBenchmark indicates whether program contains a benchmark. HasBenchmark bool `json:"hasBenchmark,omitempty"` // HasFuzz indicates whether program contains a fuzz test inside. HasFuzz bool `json:"hasFuzz,omitempty"` }
BuildResponseV2 is WASM build response for v2 api.
type DeprecatedHeader ¶
type DeprecatedHeader struct {
DeprecationWarning deprecatedMessage `json:"deprecated"`
}
DeprecatedHeader is embeddable struct to mark in response that method is deprecated.
type ErrorResponse ¶
type ErrorResponse struct { // Error is error message Error string `json:"error"` // contains filtered or unexported fields }
ErrorResponse is error response
func NewErrorResponse ¶
func NewErrorResponse(err error) *ErrorResponse
NewErrorResponse is ErrorResponse constructor
func (*ErrorResponse) Write ¶
func (r *ErrorResponse) Write(w http.ResponseWriter) http.ResponseWriter
Write writes error to response
type FilesPayload ¶
func (FilesPayload) HasUnitTests ¶
func (p FilesPayload) HasUnitTests() bool
HasUnitTests checks whether file list contains any unit test.
Note: at the moment, func doesn't check file contents and only check file names.
func (FilesPayload) Validate ¶
func (p FilesPayload) Validate() error
Validate checks file name and contents and returns error on validation failure.
type HTTPError ¶
type HTTPError struct {
// contains filtered or unexported fields
}
HTTPError is HTTP response error
func NewBadRequestError ¶
func NewHTTPError ¶
NewHTTPError constructs a new error
func (*HTTPError) WriteResponse ¶
func (err *HTTPError) WriteResponse(rw http.ResponseWriter)
WriteResponse writes error to response
type HandlerFunc ¶
type HandlerFunc func(http.ResponseWriter, *http.Request) error
HandlerFunc is langserver request handler
func DeprecatedEndpoint ¶
func DeprecatedEndpoint(h HandlerFunc, sunsetDate time.Time) HandlerFunc
type PlaygroundVersions ¶
type PlaygroundVersions struct { // GoCurrent is a current Go version on Go playground. GoCurrent string `json:"current"` // GoPrevious is a previous Go version on Go playground. GoPrevious string `json:"goprev"` // GoTip is a dev branch Go version on Go playground. GoTip string `json:"gotip"` }
PlaygroundVersions contains information about playground Go versions.
func (*PlaygroundVersions) SetBackendVersion ¶
func (vers *PlaygroundVersions) SetBackendVersion(backend goplay.Backend, version string)
type RunParams ¶
type RunParams struct { // Vet enables go vet Vet bool // Format identifies whether to format code before run. // // Deprecated and used only for v1. Format bool // Backend is Go run backend. Backend string }
RunParams is code run request parameters
type RunResponse ¶
type RunResponse struct { // Formatted contains goimport'ed code. // // Deprecated and will be removed after api/v1 sunset. Formatted string `json:"formatted,omitempty"` // Events is list of code execution outputs Events []*goplay.CompileEvent `json:"events,omitempty"` }
RunResponse is code run response
type ServiceConfig ¶
type ServiceConfig struct {
Version string
}
type ShareResponse ¶
type ShareResponse struct { string `json:"snippetID"` }SnippetID
ShareResponse is snippet share response
type SnippetResponse ¶
type SnippetResponse struct { // FileName is snippet file name FileName string `json:"fileName"` // Code is snippet source Code string `json:"code"` }
SnippetResponse is snippet response
type SpaFileServer ¶
type SpaFileServer struct { NotFoundHandler http.Handler // contains filtered or unexported fields }
SpaFileServer is a wrapper around http.FileServer for serving SPA contents.
func NewSpaFileServer ¶
func NewSpaFileServer(root string, tplVars TemplateArguments) *SpaFileServer
NewSpaFileServer returns SPA handler
func (*SpaFileServer) ServeHTTP ¶
func (fs *SpaFileServer) ServeHTTP(rw http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler
type SuggestionRequest ¶
type SuggestionRequest struct { PackageName string `json:"packageName"` Value string `json:"value"` }
SuggestionRequest is code completion suggestion request
func (SuggestionRequest) Trim ¶
func (sr SuggestionRequest) Trim() SuggestionRequest
Trim trims request payload
type SuggestionsResponse ¶
type SuggestionsResponse struct { DeprecatedHeader // Suggestions are list of suggestions for monaco Suggestions []monaco.CompletionItem `json:"suggestions"` }
SuggestionsResponse is code completion response
func (SuggestionsResponse) Write ¶
func (r SuggestionsResponse) Write(w http.ResponseWriter)
Write writes data to response
type TemplateArguments ¶
type TemplateArguments struct {
GoogleTagID string
}
type TemplateFileServer ¶
type TemplateFileServer struct {
// contains filtered or unexported fields
}
func NewTemplateFileServer ¶
func NewTemplateFileServer(logger *zap.Logger, filePath string, tplVars TemplateArguments) *TemplateFileServer
NewTemplateFileServer returns handler which compiles and serves HTML page template.
func (*TemplateFileServer) ServeHTTP ¶
func (fs *TemplateFileServer) ServeHTTP(rw http.ResponseWriter, r *http.Request)
type VersionResponse ¶
type VersionResponse struct { // Version is server version Version string `json:"version"` // APIVersion is server API version APIVersion string `json:"apiVersion"` }
VersionResponse is version response
func (VersionResponse) Write ¶
func (r VersionResponse) Write(w http.ResponseWriter)
Write writes data to response
type VersionsInformation ¶
type VersionsInformation struct { // Playground contains information about Go versions on Go Playground server. Playground *PlaygroundVersions `json:"playground"` // WebAssembly is host Go version used for building WebAssembly Go files. WebAssembly string `json:"wasm"` }
VersionsInformation contains Go version for different run targets.