Documentation
¶
Overview ¶
Package backends provides generic interfaces for HTTP server backends This allows the application to work with different web frameworks
Index ¶
- type AuthBackend
- type Backend
- type CORSBackend
- type CORSConfig
- type Context
- type Engine
- type FullBackend
- type HandlerFunc
- type LogFormatter
- type LogFormatterParams
- type LoggingBackend
- type MiddlewareFunc
- type RealtimeBackend
- type RealtimeConnection
- type RealtimeEventHandler
- type RealtimeSubscription
- type RealtimeSubscriptionController
- type ResponseWriter
- type Server
- type TestableRealtimeEventHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthBackend ¶
type AuthBackend interface {
Backend
// Authentication middleware
BasicAuth(accounts map[string]string) MiddlewareFunc
}
AuthBackend represents a backend that supports authentication middleware
type Backend ¶
type Backend interface {
// Factory methods
NewEngine() Engine
NewEngineWithDefaults() Engine
NewServer(port int, engine Engine) Server
NewServerWithAddr(addr string, engine Engine) Server
// Backend-specific configuration
SetMode(mode string)
GetMode() string
// Common middleware
Logger() MiddlewareFunc
Recovery() MiddlewareFunc
}
Backend represents a complete HTTP backend implementation
type CORSBackend ¶
type CORSBackend interface {
Backend
// CORS middleware
CORS() MiddlewareFunc
CORSWithConfig(config CORSConfig) MiddlewareFunc
}
CORSBackend represents a backend that supports CORS middleware
type CORSConfig ¶
type CORSConfig struct {
AllowOrigins []string
AllowMethods []string
AllowHeaders []string
ExposeHeaders []string
AllowCredentials bool
MaxAge time.Duration
}
CORSConfig represents CORS configuration options
type Context ¶
type Context interface {
// Request/Response handling
String(code int, format string, values ...interface{})
JSON(code int, obj interface{})
XML(code int, obj interface{})
Data(code int, contentType string, data []byte)
Status(code int)
// Request access
Request() *http.Request
ReadBody() ([]byte, error)
// Headers
GetHeader(key string) string
Header(key, value string)
// URL parameters and query strings
Param(key string) string
Query(key string) string
DefaultQuery(key, defaultValue string) string
// Form data
PostForm(key string) string
DefaultPostForm(key, defaultValue string) string
// Data binding
Bind(obj interface{}) error
ShouldBind(obj interface{}) error
BindJSON(obj interface{}) error
ShouldBindJSON(obj interface{}) error
// Context storage
Set(key string, value interface{})
Get(key string) (value interface{}, exists bool)
GetString(key string) string
GetBool(key string) bool
GetInt(key string) int
GetInt64(key string) int64
GetFloat64(key string) float64
// Flow control
Abort()
AbortWithStatus(code int)
AbortWithStatusJSON(code int, jsonObj interface{})
IsAborted() bool
Next()
}
Context represents a generic HTTP request/response context
type Engine ¶
type Engine interface {
// HTTP methods
GET(relativePath string, handlers ...HandlerFunc)
POST(relativePath string, handlers ...HandlerFunc)
PUT(relativePath string, handlers ...HandlerFunc)
DELETE(relativePath string, handlers ...HandlerFunc)
PATCH(relativePath string, handlers ...HandlerFunc)
// Middleware
Use(middleware ...HandlerFunc)
// HTTP Handler for integration with net/http
Handler() http.Handler
}
Engine represents a generic HTTP engine/router
type FullBackend ¶
type FullBackend interface {
Backend
RealtimeBackend
}
FullBackend represents a complete backend implementation with both HTTP and realtime support
type HandlerFunc ¶
type HandlerFunc func(Context)
HandlerFunc represents a generic HTTP handler function
type LogFormatter ¶
type LogFormatter func(params LogFormatterParams) string
LogFormatter represents a log formatter function
type LogFormatterParams ¶
type LogFormatterParams struct {
Request *http.Request
TimeStamp time.Time
StatusCode int
Latency time.Duration
ClientIP string
Method string
Path string
ErrorMessage string
BodySize int
Keys map[string]interface{}
}
LogFormatterParams contains the parameters for log formatting
type LoggingBackend ¶
type LoggingBackend interface {
Backend
// Logging middleware with custom configuration
LoggerWithFormatter(formatter LogFormatter) MiddlewareFunc
LoggerWithWriter(out io.Writer, notlogged ...string) MiddlewareFunc
}
LoggingBackend represents a backend that supports custom logging
type MiddlewareFunc ¶
type MiddlewareFunc = HandlerFunc
MiddlewareFunc is an alias for HandlerFunc to represent middleware
type RealtimeBackend ¶
type RealtimeBackend interface {
// CreateConnection creates a connection from a raw connection (e.g., *websocket.Conn)
CreateConnection(rawConn interface{}) (RealtimeConnection, error)
// CreateEventHandler creates an event handler
CreateEventHandler(relayServer interface{}) RealtimeEventHandler
// CreateTestableEventHandler creates a testable event handler
CreateTestableEventHandler(relayServer interface{}) TestableRealtimeEventHandler
// CreateSubscriptionController creates a subscription controller
CreateSubscriptionController(eventHandler RealtimeEventHandler) RealtimeSubscriptionController
}
RealtimeBackend represents a backend that supports realtime communication
type RealtimeConnection ¶
type RealtimeConnection interface {
// WriteMessage sends a message through the connection
WriteMessage(msgType int, data []byte) error
// Close closes the connection
Close() error
// IsOpen returns true if the connection is still open
IsOpen() bool
}
RealtimeConnection represents a generic realtime connection interface This abstracts away specific transport implementations (WebSocket, gRPC, libp2p, etc.)
type RealtimeEventHandler ¶
type RealtimeEventHandler interface {
// Signal sends a process event to all registered listeners
Signal(process *core.Process)
// Subscribe registers a subscription and returns channels for process events and errors
Subscribe(executorType string, state int, processID string, ctx context.Context) (chan *core.Process, chan error)
// WaitForProcess waits for a specific process state change
WaitForProcess(executorType string, state int, processID string, ctx context.Context) (*core.Process, error)
// Stop stops the event handler
Stop()
}
RealtimeEventHandler handles process events and manages subscriptions
type RealtimeSubscription ¶
type RealtimeSubscription struct {
Connection RealtimeConnection
MsgType int
Timeout int
ExecutorType string
State int
ProcessID string
}
RealtimeSubscription represents a subscription to process events
type RealtimeSubscriptionController ¶
type RealtimeSubscriptionController interface {
// AddProcessesSubscriber adds a subscription for all processes of a certain type
AddProcessesSubscriber(executorID string, subscription *RealtimeSubscription) error
// AddProcessSubscriber adds a subscription for a specific process
AddProcessSubscriber(executorID string, process *core.Process, subscription *RealtimeSubscription) error
}
RealtimeSubscriptionController manages subscriptions using the abstract Connection interface
type ResponseWriter ¶
type ResponseWriter interface {
http.ResponseWriter
// Additional methods that some frameworks provide
Size() int
Status() int
Written() bool
WriteHeaderNow()
}
ResponseWriter represents a generic response writer interface
type Server ¶
type Server interface {
// Server lifecycle
ListenAndServe() error
ListenAndServeTLS(certFile, keyFile string) error
Shutdown(ctx context.Context) error
ShutdownWithTimeout(timeout time.Duration) error
// Configuration
SetAddr(addr string)
GetAddr() string
SetReadTimeout(timeout time.Duration)
SetWriteTimeout(timeout time.Duration)
SetIdleTimeout(timeout time.Duration)
SetReadHeaderTimeout(timeout time.Duration)
// Access to underlying components
Engine() Engine
HTTPServer() *http.Server
}
Server represents a generic HTTP server
type TestableRealtimeEventHandler ¶
type TestableRealtimeEventHandler interface {
RealtimeEventHandler
// NumberOfListeners returns listener counts for testing
NumberOfListeners(executorType string, state int) (int, int, int)
// HasStopped returns whether the handler has stopped for testing
HasStopped() bool
}
TestableRealtimeEventHandler extends RealtimeEventHandler with methods for testing
Directories
¶
| Path | Synopsis |
|---|---|
|
Package gin provides a wrapper around the Gin web framework This package exposes commonly used Gin functionality through a clean interface while maintaining compatibility with the underlying gin.Engine and gin.Context
|
Package gin provides a wrapper around the Gin web framework This package exposes commonly used Gin functionality through a clean interface while maintaining compatibility with the underlying gin.Engine and gin.Context |