Documentation
¶
Index ¶
- Constants
- type CORSConfig
- type Context
- func (c *Context) BindJSON(v any) error
- func (c *Context) BindJSONLimit(v any, limit int64) error
- func (c *Context) BindJSONStrict(v any, limit int64) error
- func (c *Context) HTML(code int, html string) error
- func (c *Context) JSON(code int, data any) error
- func (c *Context) NoContent() error
- func (c *Context) Param(key string) string
- func (c *Context) Query(key string) string
- func (c *Context) QueryDefault(key, defaultVal string) string
- func (c *Context) Redirect(code int, url string) error
- func (c *Context) SSE() (*SSEWriter, error)
- func (c *Context) SetHeader(key, value string)
- func (c *Context) SetWriteDeadline(t time.Time) error
- func (c *Context) StreamJSON(dataChan <-chan any) error
- func (c *Context) String(code int, msg string) error
- type Engine
- func (e *Engine) DELETE(path string, h HandlerFunc)
- func (e *Engine) GET(path string, h HandlerFunc)
- func (e *Engine) Group(prefix string) *Group
- func (e *Engine) HEAD(path string, h HandlerFunc)
- func (e *Engine) Handle(method, pattern string, handler HandlerFunc)
- func (e *Engine) Listen(addr string) error
- func (e *Engine) OPTIONS(path string, h HandlerFunc)
- func (e *Engine) PATCH(path string, h HandlerFunc)
- func (e *Engine) POST(path string, h HandlerFunc)
- func (e *Engine) PUT(path string, h HandlerFunc)
- func (e *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (e *Engine) Server(addr string) *http.Server
- func (e *Engine) Use(middleware ...MiddlewareFunc)
- func (e *Engine) Wrap(middleware ...HTTPMiddleware)
- type Group
- func (g *Group) DELETE(path string, h HandlerFunc)
- func (g *Group) GET(path string, h HandlerFunc)
- func (g *Group) Group(prefix string) *Group
- func (g *Group) HEAD(path string, h HandlerFunc)
- func (g *Group) Handle(method, path string, handler HandlerFunc)
- func (g *Group) OPTIONS(path string, h HandlerFunc)
- func (g *Group) PATCH(path string, h HandlerFunc)
- func (g *Group) POST(path string, h HandlerFunc)
- func (g *Group) PUT(path string, h HandlerFunc)
- func (g *Group) Use(middleware ...MiddlewareFunc)
- type HTTPError
- type HTTPMiddleware
- type HandlerFunc
- type MiddlewareFunc
- type SSEWriter
Constants ¶
const ( DefaultReadHeaderTimeout = 5 * time.Second DefaultReadTimeout = 30 * time.Second DefaultWriteTimeout = 60 * time.Second DefaultIdleTimeout = 120 * time.Second DefaultMaxHeaderBytes = 64 << 10 )
Default server timeouts applied by Engine.Server and Engine.Listen. Handlers that legitimately run longer (streaming, long tool batches) extend their own write deadline with Context.SetWriteDeadline.
const DefaultMaxBodyBytes int64 = 1 << 20
DefaultMaxBodyBytes is the request body limit applied by BindJSON.
const StreamWriteTimeout = 10 * time.Second
StreamWriteTimeout bounds each individual write of a stream, so a client that stops reading cannot hold the handler forever. It also replaces the server-wide WriteTimeout for the lifetime of the stream.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CORSConfig ¶
type CORSConfig struct {
AllowOrigins []string
AllowMethods []string
AllowHeaders []string
// MaxAge is how long browsers may cache a preflight answer (0 = unset).
MaxAge time.Duration
}
CORSConfig defines CORS options
func DefaultCORSConfig ¶
func DefaultCORSConfig() CORSConfig
DefaultCORSConfig provides defaults that allow any origin. Restrict AllowOrigins for anything that is not a public API.
type Context ¶
type Context struct {
ResponseWriter http.ResponseWriter
Request *http.Request
// contains filtered or unexported fields
}
Context wraps the request and response for convenient access
func (*Context) BindJSON ¶
BindJSON decodes a single JSON value from the request body, limited to DefaultMaxBodyBytes. Failures are *HTTPError (413 or 400).
func (*Context) BindJSONLimit ¶
BindJSONLimit is BindJSON with an explicit body size limit in bytes.
func (*Context) BindJSONStrict ¶
BindJSONStrict is BindJSONLimit that also rejects unknown object fields.
func (*Context) JSON ¶
JSON sends a JSON response. The value is encoded before anything is written, so an unencodable value returns an error with the response still uncommitted.
func (*Context) QueryDefault ¶
QueryDefault returns a query parameter or a default value if not set
func (*Context) SSE ¶
SSE starts a text/event-stream response and flushes the headers. It returns an error, with nothing committed, if the response writer cannot flush.
func (*Context) SetWriteDeadline ¶
SetWriteDeadline sets the write deadline of the underlying connection, for handlers that legitimately run longer than the server WriteTimeout. It returns an error wrapping http.ErrNotSupported when the server cannot.
func (*Context) StreamJSON ¶
StreamJSON streams values from dataChan as newline-delimited JSON (application/x-ndjson), flushing after each value. It returns nil when the channel is closed and the request context's error when the client goes away, even while idle. Producers must stop on the same context: a producer blocked sending to an abandoned channel would leak.
type Engine ¶
type Engine struct {
// ErrorHandler renders an error returned by a handler before any response
// bytes were written. The default maps *HTTPError to its status and
// message and answers 500 "Internal Server Error" for everything else,
// without leaking the error text. Set it before serving.
ErrorHandler func(*Context, error)
// contains filtered or unexported fields
}
Engine is the core framework instance. Routing is delegated to the standard library http.ServeMux, so route patterns use its syntax:
/users/{id} single-segment parameter
/files/{path...} remaining path (may be empty)
/{$} exactly "/"
Static segments take precedence over parameters, and registering two patterns that overlap ambiguously (or the same pattern and method twice) panics at registration time.
func (*Engine) DELETE ¶
func (e *Engine) DELETE(path string, h HandlerFunc)
func (*Engine) Group ¶
Group creates a new route group with a shared prefix. The prefix must be empty or start with "/" and must not end with "/".
func (*Engine) HEAD ¶
func (e *Engine) HEAD(path string, h HandlerFunc)
func (*Engine) Handle ¶
func (e *Engine) Handle(method, pattern string, handler HandlerFunc)
Handle registers a route with any HTTP method. A GET route also answers HEAD, as with net/http.
func (*Engine) OPTIONS ¶
func (e *Engine) OPTIONS(path string, h HandlerFunc)
func (*Engine) PATCH ¶
func (e *Engine) PATCH(path string, h HandlerFunc)
func (*Engine) POST ¶
func (e *Engine) POST(path string, h HandlerFunc)
func (*Engine) PUT ¶
func (e *Engine) PUT(path string, h HandlerFunc)
func (*Engine) ServeHTTP ¶
func (e *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler
func (*Engine) Server ¶
Server returns an http.Server serving this engine with safe default timeouts. Adjust the fields (TLSConfig, timeouts, BaseContext...) before calling ListenAndServe or Serve.
func (*Engine) Use ¶
func (e *Engine) Use(middleware ...MiddlewareFunc)
Use adds global per-route middleware. It applies to routes registered after the call; the first Use call is the outermost middleware.
func (*Engine) Wrap ¶
func (e *Engine) Wrap(middleware ...HTTPMiddleware)
Wrap adds HTTP middleware around the entire engine (outside routing). The first Wrap call is the outermost layer. It panics if the engine already served a request.
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group represents a route group with a shared prefix and middleware
func (*Group) DELETE ¶
func (g *Group) DELETE(path string, h HandlerFunc)
func (*Group) Group ¶
Group creates a nested group that inherits a copy of this group's middleware at creation time.
func (*Group) HEAD ¶
func (g *Group) HEAD(path string, h HandlerFunc)
func (*Group) Handle ¶
func (g *Group) Handle(method, path string, handler HandlerFunc)
Handle registers a route within the group
func (*Group) OPTIONS ¶
func (g *Group) OPTIONS(path string, h HandlerFunc)
func (*Group) PATCH ¶
func (g *Group) PATCH(path string, h HandlerFunc)
func (*Group) POST ¶
func (g *Group) POST(path string, h HandlerFunc)
func (*Group) PUT ¶
func (g *Group) PUT(path string, h HandlerFunc)
func (*Group) Use ¶
func (g *Group) Use(middleware ...MiddlewareFunc)
Use adds middleware to this group. Group middleware runs inside engine middleware and applies to routes registered after the call.
type HTTPError ¶
HTTPError is an error with an HTTP status. The default Engine error handler renders it as a plain-text response with Message (or the status text).
type HTTPMiddleware ¶
HTTPMiddleware wraps the whole engine, before routing and method dispatch. Use it (through Engine.Wrap) for concerns that must also see unmatched requests and preflights, such as CORS.
func CORS ¶
func CORS(config ...CORSConfig) HTTPMiddleware
CORS returns HTTP middleware that handles CORS. Register it with Engine.Wrap so preflight requests are answered before routing and method dispatch, whether or not an OPTIONS route exists.
Requests from origins that are not allowed pass through untouched, without CORS headers. Credentials are never allowed.
type HandlerFunc ¶
HandlerFunc defines the handler signature with error return
type MiddlewareFunc ¶
type MiddlewareFunc func(HandlerFunc) HandlerFunc
MiddlewareFunc defines the per-route middleware signature. It wraps a HandlerFunc at registration time and runs only for matched routes.
func Recovery ¶
func Recovery() MiddlewareFunc
Recovery returns a middleware that recovers from panics. The panic becomes an error returned to the engine, so it is rendered by the normal error handler, or only logged when the response was already started.
type SSEWriter ¶
type SSEWriter struct {
// contains filtered or unexported fields
}
SSEWriter writes Server-Sent Events from the handler goroutine. There is no producer goroutine or channel: the caller emits events as work completes.
Directories
¶
| Path | Synopsis |
|---|---|
|
Command main is a local tool-execution server built on Blaze.
|
Command main is a local tool-execution server built on Blaze. |
|
agent-loop
command
Command agent-loop runs a complete model round trip with Blaze's built-in tools, against OpenAI and against Anthropic.
|
Command agent-loop runs a complete model round trip with Blaze's built-in tools, against OpenAI and against Anthropic. |
|
mcp
module
|
|