handler

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHTTPErrorHandler

func NewHTTPErrorHandler() echo.HTTPErrorHandler

NewHTTPErrorHandler returns a custom echo.HTTPErrorHandler that renders framework-level errors (404, 405, etc.) in the unified ErrorResponse format.

Types

type ErrorCode

type ErrorCode string

ErrorCode is a typed string for structured error codes.

const (
	CodeInvalidRequestBody  ErrorCode = "INVALID_REQUEST_BODY"
	CodeValidationError     ErrorCode = "VALIDATION_ERROR"
	CodeInternalError       ErrorCode = "INTERNAL_ERROR"
	CodeTimeout             ErrorCode = "TIMEOUT"
	CodeNotFound            ErrorCode = "NOT_FOUND"
	CodeMethodNotAllowed    ErrorCode = "METHOD_NOT_ALLOWED"
	CodeRequestBodyTooLarge ErrorCode = "REQUEST_BODY_TOO_LARGE"
	CodeServerBusy          ErrorCode = "SERVER_BUSY"
)

func (ErrorCode) Message

func (c ErrorCode) Message() string

Message returns the canonical human-readable message for the error code.

type ErrorResponse

type ErrorResponse struct {
	Code    ErrorCode         `json:"code"`
	Message string            `json:"message"`
	Errors  []ValidationError `json:"errors,omitempty"`
}

ErrorResponse is the unified JSON error response body.

type File

type File struct {
	Name          *string `json:"name"`
	Content       *string `json:"content"`
	Base64Encoded bool    `json:"base64_encoded"`
}

File represents a single source file in the run request. The first file in the request's Files array is used as the entrypoint.

func (File) Validate

func (f File) Validate() error

Validate checks that f.Name is safe to use as a flat filename. It rejects nil, empty names, names containing '/' or null bytes, and "." / "..". Because all slashes are rejected here, writeFiles does not need a secondary path traversal check after filepath.Join.

type Handler

type Handler struct {
	Runner      *sandbox.Runner
	MaxFiles    int
	MaxFileSize int
	// MaxStdinSize bounds the post-decode stdin length in bytes. For
	// base64-encoded stdin this is the decoded byte count, not the wire
	// string length. The raw request body is independently bounded by
	// Echo's BodyLimit middleware configured at server startup; if
	// MaxStdinSize exceeds the body limit, the body limit wins.
	MaxStdinSize int
}

Handler holds dependencies for the HTTP handler.

func (*Handler) RunHandler

func (h *Handler) RunHandler(c *echo.Context) error

type RunRequest

type RunRequest struct {
	Runtime *string     `json:"runtime"`
	Files   []File      `json:"files"`
	Stdin   *StdinInput `json:"stdin"`
}

RunRequest is the JSON request body for POST /v1/run.

type RunResponse

type RunResponse struct {
	Compile *sandbox.Result `json:"compile"`
	Run     *sandbox.Result `json:"run"`
}

RunResponse is the JSON response for POST /v1/run. Compile is nil for interpreted runtimes. Run is nil when compilation fails.

type StdinInput added in v0.9.0

type StdinInput struct {
	Content       *string `json:"content"`
	Base64Encoded bool    `json:"base64_encoded"`
}

StdinInput represents the optional stdin payload in a run request. The payload is delivered only to the run-step child process; compile-step children never receive stdin. When the top-level "stdin" field is omitted, the RunRequest.Stdin pointer is nil. When present, Content is required: a nil Content (e.g. JSON `"stdin": {}`) produces a `required` validation error. When Base64Encoded is true, Content is interpreted as a base64-encoded string and decoded server-side; when false (the default), the raw bytes of Content are forwarded to the run-step child's stdin directly.

type ValidationError

type ValidationError struct {
	Path    []any  `json:"path"`
	Message string `json:"message"`
}

ValidationError describes a field-level validation failure.

Jump to

Keyboard shortcuts

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