Documentation
¶
Index ¶
- type Context
- type FWContext
- func (c *FWContext) BindJSON(out any) error
- func (c *FWContext) Body() []byte
- func (c *FWContext) Container() inject.Injector
- func (c *FWContext) Get(key string) (any, bool)
- func (c *FWContext) GetInt(key string) int
- func (c *FWContext) GetString(key string) string
- func (c *FWContext) Header(name string) string
- func (c *FWContext) Headers() map[string]string
- func (c *FWContext) Host() string
- func (c *FWContext) Method() string
- func (c *FWContext) MustGet(key string) any
- func (c *FWContext) Param(name string) string
- func (c *FWContext) Params() map[string]string
- func (c *FWContext) Path() string
- func (c *FWContext) Queries() map[string]string
- func (c *FWContext) Query(name string) string
- func (c *FWContext) Raw() *fasthttp.RequestCtx
- func (c *FWContext) RawResponse() ResponseBuilder
- func (c *FWContext) Respond(statusCode int, code int, message string, data any) error
- func (c *FWContext) SSE(fn func(w *SSEWriter)) error
- func (c *FWContext) Scheme() string
- func (c *FWContext) Set(key string, value any)
- func (c *FWContext) SetContainer(i inject.Injector)
- func (c *FWContext) SetRouteParams(p map[string]string)
- func (c *FWContext) SetTraceIDFunc(fn func(*fasthttp.RequestCtx) string)
- func (c *FWContext) StatusOK(message ...string) ResponseBuilder
- func (c *FWContext) StatusParamError(message ...string) ResponseBuilder
- func (c *FWContext) StatusServerError(message ...string) ResponseBuilder
- func (c *FWContext) TraceID() string
- func (c *FWContext) URI() string
- type ResponseBuilder
- type SSEWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context interface {
Raw() *fasthttp.RequestCtx
Method() string
Scheme() string
Host() string
Path() string
URI() string
Header(name string) string
Headers() map[string]string
Param(name string) string
Params() map[string]string
Query(name string) string
Queries() map[string]string
Body() []byte
BindJSON(out any) error
Respond(statusCode int, code int, message string, data any) error
RawResponse() ResponseBuilder
StatusOK(message ...string) ResponseBuilder
StatusParamError(message ...string) ResponseBuilder
StatusServerError(message ...string) ResponseBuilder
Container() inject.Injector
SetContainer(inject.Injector)
SetRouteParams(map[string]string)
TraceID() string
// Set stores a key-value pair in the request-scoped context.
// Typically used by middleware to pass data (e.g. user info) to handlers or later middleware.
Set(key string, value any)
// Get retrieves a value by key from the request-scoped context.
// Returns the value and whether the key was found.
Get(key string) (any, bool)
// MustGet retrieves a value by key, panics if the key does not exist.
MustGet(key string) any
// GetString is a convenience method that returns the value as a string.
// Returns empty string if the key is missing or the value is not a string.
GetString(key string) string
// GetInt is a convenience method that returns the value as an int.
// Returns 0 if the key is missing or the value is not an int.
GetInt(key string) int
// SSE starts a Server-Sent Events stream.
// It sets the appropriate headers (Content-Type, Cache-Control, Connection) and
// returns an SSEWriter that can be used to send events to the client.
// The provided callback receives the writer; when the callback returns, the stream ends.
SSE(fn func(w *SSEWriter)) error
}
type FWContext ¶
type FWContext struct {
// contains filtered or unexported fields
}
func (*FWContext) Raw ¶
func (c *FWContext) Raw() *fasthttp.RequestCtx
func (*FWContext) RawResponse ¶
func (c *FWContext) RawResponse() ResponseBuilder
func (*FWContext) SSE ¶
SSE starts a Server-Sent Events stream. It sets appropriate headers and invokes fn with an SSEWriter. The stream is closed when fn returns.
Usage:
ctx.SSE(func(w *SSEWriter) {
w.WriteText("hello")
w.WriteJSON(map[string]any{"count": 1})
w.WriteEvent("update", "payload data")
})
func (*FWContext) SetContainer ¶
func (*FWContext) SetRouteParams ¶
func (*FWContext) SetTraceIDFunc ¶
func (c *FWContext) SetTraceIDFunc(fn func(*fasthttp.RequestCtx) string)
func (*FWContext) StatusOK ¶
func (c *FWContext) StatusOK(message ...string) ResponseBuilder
func (*FWContext) StatusParamError ¶
func (c *FWContext) StatusParamError(message ...string) ResponseBuilder
func (*FWContext) StatusServerError ¶
func (c *FWContext) StatusServerError(message ...string) ResponseBuilder
type ResponseBuilder ¶
type ResponseBuilder interface {
Message(message string) ResponseBuilder
Code(code int) ResponseBuilder
Data(data any) error
Send() error
}
type SSEWriter ¶
type SSEWriter struct {
// contains filtered or unexported fields
}
SSEWriter writes Server-Sent Events to an underlying buffered writer. Each method writes a complete SSE frame and flushes immediately.
func (*SSEWriter) WriteEvent ¶
WriteEvent sends a named SSE event with text data.
event: <event>\ndata: <data>\n\n
func (*SSEWriter) WriteEventJSON ¶
WriteEventJSON sends a named SSE event with JSON-encoded data.
event: <event>\ndata: <json>\n\n
func (*SSEWriter) WriteID ¶
WriteID sends an SSE event with id, event name, and text data.
id: <id>\nevent: <event>\ndata: <data>\n\n
Click to show internal directories.
Click to hide internal directories.