server

package
v1.15.1-0...-ab84f35 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IndexFileName    = "index.html"
	NotFoundFileName = "404.html"
)
View Source
const (
	VersionCacheTTL = 24 * time.Hour
)

Variables

View Source
var ErrEmptyRequest = errors.New("empty request")
View Source
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

func ServeFileWithStatus(rw http.ResponseWriter, r *http.Request, name string, code int)

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 APIv2HandlerConfig struct {
	Client       *goplay.Client
	Builder      builder.BuildService
	BuildTimeout time.Duration
}

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 NewBackendVersionService

func NewBackendVersionService(logger *zap.Logger, client *goplay.Client, cacheTTL time.Duration) *BackendVersionService

func (*BackendVersionService) GetVersions

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

Write writes error to response

type FilesPayload

type FilesPayload struct {
	Files map[string]string `json:"files"`
}

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 GuardFn

type GuardFn func(r *http.Request) error

GuardFn is guard middleware handler

type HTTPError

type HTTPError struct {
	// contains filtered or unexported fields
}

HTTPError is HTTP response error

func Errorf

func Errorf(code int, format string, args ...interface{}) *HTTPError

Errorf returns new formatted error

func NewBadRequestError

func NewBadRequestError(err error) *HTTPError

func NewHTTPError

func NewHTTPError(code int, err error) *HTTPError

NewHTTPError constructs a new error

func (*HTTPError) Error

func (err *HTTPError) Error() string

Error implements error

func (*HTTPError) Unwrap

func (err *HTTPError) Unwrap() error

Unwrap implements 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

func RunParamsFromQuery

func RunParamsFromQuery(query url.Values) (params RunParams, err error)

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 {
	// SnippetID is definitely not a snippet id (sarcasm)
	SnippetID string `json:"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

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

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL