handler

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 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
}

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"`
}

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