github.com/goceleris/celeris
Package celeris provides an ultra-low latency HTTP server with dual-architecture I/O (io_uring + epoll) and a high-level API for routing and request handling. Routes support static paths, named parameters, and catch-all wildcards: Access matched parameters by name. Type-safe parsing methods are available: Query parameters support defaults and multi-values: Middleware is provided by the github.com/goceleris/middlewares module. Use Server.Use to register middleware globally or per route group. To write custom middleware, use the HandlerFunc signature and call Context.Next to invoke downstream handlers. Next returns the first error from downstream, which middleware can handle or propagate: Handlers return errors. Unhandled errors are caught by the routerAdapter safety net: *HTTPError writes its Code+Message; bare errors write 500. Middleware can intercept errors from downstream handlers: Register a global error handler with Server.OnError. This is called when an unhandled error reaches the safety net after all middleware has had its chance. Use it to render structured error responses (e.g. JSON) instead of the default text/plain fallback: If the handler does not write a response, the default text/plain fallback applies. OnError must be called before Start. On Linux, choose between IOUring, Epoll, Adaptive, or Std engines. On other platforms, only Std is available. The Protocol field controls HTTP version negotiation: Example: Wrap existing net/http handlers. Response bodies from adapted handlers are buffered in memory (capped at 100 MB). Context objects are pooled and recycled between requests. Do not retain references to a *Context after the handler returns. Copy any needed values before returning. For the request body specifically, use Context.BodyCopy to obtain a copy that outlives the handler: When using Detach, the returned done function MUST be called — failure to do so permanently leaks the Context from the pool. The Server.Collector method returns an observe.Collector that records per-request metrics (throughput, latency histogram, error rate, active connections). Use Collector.Snapshot to retrieve a point-in-time copy: For Prometheus or debug endpoint integration, see the github.com/goceleris/middlewares module. Config.Workers controls the number of I/O workers (default: GOMAXPROCS). Config.ShutdownTimeout sets the graceful shutdown deadline for StartWithContext (default: 30s). Assign names to routes with Route.Name, then generate URLs via Server.URL: For catch-all routes the value replaces the wildcard segment: Use Server.Routes to list all registered routes. Parse url-encoded and multipart form bodies: For file uploads, use FormFile or MultipartForm: Serve static files with automatic content-type detection and Range support: Callers must sanitize user-supplied paths to prevent directory traversal. Serve an entire directory under a URL prefix: This is equivalent to: For simple cases, stream an io.Reader as a buffered response (capped at 100 MB): For true incremental streaming (SSE, chunked responses), use StreamWriter with the Detach pattern: StreamWriter returns nil if the engine does not support streaming. The std engine supports streaming; native engines (io_uring, epoll) will support it in a future release. Read and write cookies: Extract HTTP Basic Authentication credentials: Bind auto-detects the format from Content-Type: Or use format-specific methods: For raw body access: Context provides typed response methods: All response methods return ErrResponseWritten if called after a response has already been sent. Inspect the Accept header and auto-select the response format: Or use Respond to auto-format based on Accept: Beyond content type, negotiate encodings and languages: Attach middleware to individual routes without creating a group: Route.Use inserts middleware before the final handler, after server/group middleware. Must be called before Server.Start. Middleware can inspect the response body after c.Next() by opting in: Middleware that needs to transform response bodies (compress, ETag, cache) uses BufferResponse to intercept and modify the response before it is sent: BufferResponse is depth-tracked: multiple middleware layers can each call BufferResponse, and the response is only sent when the outermost layer calls FlushResponse. If middleware forgets to flush, a safety net in the handler adapter auto-flushes the response. CaptureResponse and BufferResponse serve different purposes. CaptureResponse is read-only: the response is written to the wire AND a copy is captured for inspection (ideal for loggers). BufferResponse defers the wire write entirely, allowing middleware to transform the body before sending (ideal for compress, ETag, cache). If both are active, BufferResponse takes precedence. Check response state from middleware after calling c.Next(): Handlers signal HTTP errors via HTTPError: Sentinel errors for common conditions: Middleware calls Next to invoke downstream handlers. Abort stops the chain: Store request-scoped data for sharing between middleware and handlers: Set Content-Disposition headers for file downloads or inline display: Detect request characteristics: FormValueOK distinguishes a missing field from an empty value: Additional request accessors: Context.RemoteAddr returns the TCP peer address. On native engines (epoll, io_uring), the address is captured from accept(2) or getpeername(2). On the std engine, it comes from http.Request.RemoteAddr. Context.Host returns the request host, checking the :authority pseudo-header first (HTTP/2) then falling back to the Host header (HTTP/1.1): HTTP/1.1 connections can be hijacked on all engines for WebSocket or other protocols that require raw TCP access: HTTP/2 connections cannot be hijacked because multiplexed streams share a single TCP connection. Start the server with a pre-existing listener for zero-downtime deploys: In addition to the basic config fields, the following tuning fields are available: After Start or StartWithContext, Server.Addr returns the bound address. This is useful when listening on ":0" to discover the OS-assigned port: The github.com/goceleris/celeris/celeristest package provides test helpers:
proxy.golang.org
v1.2.3
about 23 hours ago
23
Links
| Registry | proxy.golang.org |
| Source | Repository |
| Docs | Documentation |
| JSON API | View JSON |
| CodeMeta | codemeta.json |
Package Details
| PURL |
pkg:golang/github.com/goceleris/celeris
spec |
| License | Apache-2.0 |
| Namespace | github.com/goceleris |
| First Release | 28 days ago |
| Last Synced | about 21 hours ago |
Repository
| Stars | 1 on GitHub |
| Forks | 1 on GitHub |