API Reference
Complete API reference for the Rue framework.
Engine
Creation
func New() *Engine
Creates a new Engine without any middleware.
func Default() *Engine
Creates a new Engine with Logger and Recovery middleware.
Routing Methods
func (e *Engine) GET(path string, handlers ...HandlerFunc)
func (e *Engine) POST(path string, handlers ...HandlerFunc)
func (e *Engine) PUT(path string, handlers ...HandlerFunc)
func (e *Engine) DELETE(path string, handlers ...HandlerFunc)
func (e *Engine) PATCH(path string, handlers ...HandlerFunc)
func (e *Engine) HEAD(path string, handlers ...HandlerFunc)
func (e *Engine) OPTIONS(path string, handlers ...HandlerFunc)
func (e *Engine) Any(path string, handlers ...HandlerFunc)
Server Methods
func (e *Engine) Run(addr string) error
Starts HTTP server on the specified address.
func (e *Engine) RunTLS(addr, certFile, keyFile string) error
Starts HTTPS server with TLS.
func (e *Engine) RunQUIC(addr, certFile, keyFile string) error
Starts HTTP/3 server with QUIC.
func (e *Engine) Shutdown(ctx context.Context) error
Gracefully shuts down the server.
Context
Request Data
func (c *Context) Param(key string) string
Returns path parameter value.
func (c *Context) Query(key string) string
Returns query parameter value.
func (c *Context) DefaultQuery(key, defaultValue string) string
Returns query parameter or default value.
func (c *Context) GetHeader(key string) string
Returns request header value.
Data Binding
func (c *Context) BindJSON(obj any) error
func (c *Context) BindXML(obj any) error
func (c *Context) BindForm(obj any) error
func (c *Context) BindQuery(obj any) error
func (c *Context) BindHeader(obj any) error
Response Methods
func (c *Context) JSON(code int, obj any)
func (c *Context) XML(code int, obj any)
func (c *Context) String(code int, format string, values ...any)
func (c *Context) Text(code int, text string)
func (c *Context) Data(code int, contentType string, data []byte)
func (c *Context) File(filepath string)
func (c *Context) Stream(code int, contentType string, reader io.Reader)
func (c *Context) Redirect(code int, location string)
Flow Control
func (c *Context) Next()
Executes the next handler in the chain.
func (c *Context) Abort()
Stops the handler chain.
func (c *Context) AbortWithStatus(code int)
Stops chain and writes status code.
func (c *Context) AbortWithError(code int, err error)
Stops chain and writes error.
Context Values
func (c *Context) Set(key string, value any)
func (c *Context) Get(key string) (any, bool)
func (c *Context) MustGet(key string) any
Middleware
func Logger() HandlerFunc
func LoggerWithConfig(config LoggerConfig) HandlerFunc
func Recovery() HandlerFunc
func CORS() HandlerFunc
func CORSWithConfig(config CORSConfig) HandlerFunc
func RateLimiter(rate float64, burst int) HandlerFunc
func RateLimiterWithConfig(config RateLimiterConfig) HandlerFunc
func JWT(secret []byte) HandlerFunc
func APIKey(validator func(string) bool) HandlerFunc
func Gzip() HandlerFunc
func Brotli() HandlerFunc
func Compress() HandlerFunc
Validation
func (c *Context) Validate(obj any) error
Validates struct using tags: required, min, max, len, email, url, regex, oneof
Types
type H map[string]any
Shortcut for map[string]any, commonly used for JSON responses.
type HandlerFunc func(*Context)
Handler function signature.