Documentation
¶
Index ¶
- Constants
- type CORSConfig
- type Context
- func (c *Context) Abort()
- func (c *Context) BindJSON(obj any) error
- func (c *Context) BindJSONReusable(obj any) error
- func (c *Context) ClearCookie(name string)
- func (c *Context) ClientIP() string
- func (c *Context) Cookie(name string) (string, error)
- func (c *Context) Copy() *Context
- func (c *Context) DefaultQuery(key string, defautlValue string) string
- func (c *Context) Error(statusCode int, err error)
- func (c *Context) FormFile(name string) (*multipart.FileHeader, error)
- func (c *Context) FormValue(key string) string
- func (c *Context) Get(key string) (value any, exists bool)
- func (c *Context) HTML(code int, name string, data interface{})
- func (c *Context) IP() string
- func (c *Context) Initialize(w http.ResponseWriter, r *http.Request, p httprouter.Params, ...)
- func (c *Context) JSON(statusCode int, obj any)
- func (c *Context) Next()
- func (c *Context) NoContent()
- func (c *Context) Param(key string) string
- func (c *Context) ParamBool(key string) (bool, error)
- func (c *Context) ParamInt(key string) (int, error)
- func (c *Context) Query(key string) string
- func (c *Context) QueryBool(key string) (bool, error)
- func (c *Context) QueryInt(key string) (int, error)
- func (c *Context) Redirect(statusCode int, location string)
- func (c *Context) Reset()
- func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string) error
- func (c *Context) Set(key string, value any)
- func (c *Context) SetCookie(name, value string, maxAge int)
- func (c *Context) Status(code int)
- func (c *Context) String(statusCode int, text string)
- func (c *Context) XML(statusCode int, obj any)
- type Engine
- func (e *Engine) AllowWSOrigins(origins []string)
- func (e *Engine) LoadHTMLFiles(files ...string) error
- func (e *Engine) LoadHTMLGlob(pattern string) error
- func (e *Engine) Run(addr string) error
- func (e *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (e *Engine) ServeSPA(root string)
- func (e *Engine) SetTrustedProxies(proxies []string) error
- type HandlerFunc
- type M
- type RouterGroup
- func (rg *RouterGroup) DELETE(path string, handler HandlerFunc)
- func (rg *RouterGroup) GET(path string, handler HandlerFunc)
- func (rg *RouterGroup) Group(prefix string, middlewares ...HandlerFunc) *RouterGroup
- func (rg *RouterGroup) HEAD(path string, handler HandlerFunc)
- func (rg *RouterGroup) PATCH(path string, handler HandlerFunc)
- func (rg *RouterGroup) POST(path string, handler HandlerFunc)
- func (rg *RouterGroup) PUT(path string, handler HandlerFunc)
- func (rg *RouterGroup) SSE(relativePath string, handler SSEHandlerFunc)
- func (rg *RouterGroup) Static(relativePath string, root string)
- func (rg *RouterGroup) Use(middlewares ...HandlerFunc)
- func (rg *RouterGroup) WS(relativePath string, handler WSHandlerFunc)
- type SSEContext
- func (sc *SSEContext) Done() <-chan struct{}
- func (sc *SSEContext) Get(key string) (value any, exists bool)
- func (sc *SSEContext) IP() string
- func (sc *SSEContext) Param(key string) string
- func (sc *SSEContext) Query(key string) string
- func (sc *SSEContext) Send(event string, data any) error
- func (sc *SSEContext) SendComment(comment string) error
- func (sc *SSEContext) SendData(data any) error
- func (sc *SSEContext) Set(key string, value any)
- type SSEHandlerFunc
- type VodkaError
- type WSConfig
- type WSContext
- func (wc *WSContext) Close() error
- func (wc *WSContext) Get(key string) (value any, exists bool)
- func (wc *WSContext) IP() string
- func (wc *WSContext) Param(key string) string
- func (wc *WSContext) Query(key string) string
- func (wc *WSContext) ReadJSON(v any) error
- func (wc *WSContext) ReadMessage() (messageType int, p []byte, err error)
- func (wc *WSContext) Set(key string, value any)
- func (wc *WSContext) WriteJSON(v any) error
- func (wc *WSContext) WriteMessage(messageType int, data []byte) error
- type WSHandlerFunc
Constants ¶
const ( Reset = "\033[0m" Red = "\033[31m" Green = "\033[32m" Yellow = "\033[33m" Blue = "\033[34m" Cyan = "\033[36m" Gray = "\033[37m" )
ANSI Color Escape Codes
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CORSConfig ¶ added in v0.3.3
CORSConfig holds configuration options for the CORS middleware
type Context ¶
type Context struct {
Writer http.ResponseWriter // net/http response writer
Request *http.Request // net/http request
Params httprouter.Params // URL Parameters for dynamic routing
Keys map[string]any // Key-Value Store
Errors []*VodkaError // Stores errors along the middleware chain
// contains filtered or unexported fields
}
func (*Context) BindJSONReusable ¶ added in v0.3.3
func (*Context) ClearCookie ¶ added in v0.2.17
ClearCookie deletes a cookie by setting its MaxAge to -1.
func (*Context) ClientIP ¶ added in v0.2.17
Helper to get actual client ip when XFF is involved. NOTE: SetTrustedProxies must be called on the engine before this method can parse X-Forwarded-For headers. Without it, ClientIP always returns RemoteAddr.
func (*Context) Cookie ¶ added in v0.2.17
Cookie returns the value of the named cookie from the request. Returns an error if the cookie is not found.
func (*Context) Copy ¶ added in v0.2.17
helper function to copy context for using it outisde the request lifecycle
func (*Context) DefaultQuery ¶
Default Query returns value if exists otherwise a default value
func (*Context) Error ¶ added in v0.2.10
Stores Errors in the context to be handled by ErrorHandler Middleware
func (*Context) FormFile ¶ added in v0.2.8
func (c *Context) FormFile(name string) (*multipart.FileHeader, error)
Retrieves a single file from multipart form
func (*Context) HTML ¶ added in v0.3.2
HTML renders an HTML template with the given status code and data
func (*Context) Initialize ¶ added in v0.2.17
func (c *Context) Initialize(w http.ResponseWriter, r *http.Request, p httprouter.Params, handlers []HandlerFunc, e *Engine)
helper to initialize Context
func (*Context) Next ¶
func (c *Context) Next()
Step By Step execution of middlewares doesnt handle abort
func (*Context) SaveUploadedFile ¶ added in v0.2.8
func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string) error
Saves Uploaded File to destination on disk
func (*Context) Set ¶ added in v0.2.7
Set Values into Keys into the context to be used later by another middleware
func (*Context) SetCookie ¶ added in v0.2.17
SetCookie writes a cookie to the response. maxAge is in seconds. Use 0 for session cookie, negative to delete.
type Engine ¶
type Engine struct {
WSConfig *WSConfig
*RouterGroup
// contains filtered or unexported fields
}
httprouter wrapper
func DefaultRouter ¶ added in v0.1.1
func DefaultRouter() *Engine
func (*Engine) AllowWSOrigins ¶ added in v0.2.16
AllowWSOrigins whitelists the given origins for WebSocket upgrade requests. Call this before registering WS routes.
app.AllowWSOrigins([]string{"https://userapp.com", "https://admin.com"})
func (*Engine) LoadHTMLFiles ¶ added in v0.3.2
LoadHTMLFiles parses and caches specific template files
func (*Engine) LoadHTMLGlob ¶ added in v0.3.2
LoadHTMLGlob parses and caches templates from a glob pattern
func (*Engine) ServeHTTP ¶ added in v0.2.5
func (e *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP intercepts every request before it hits the router
func (*Engine) SetTrustedProxies ¶ added in v0.2.17
Sets trusted Proxies
type HandlerFunc ¶
type HandlerFunc func(*Context) // Handler Function with Context wrapping
func AllowCORS ¶ added in v0.2.1
func AllowCORS(origins []string, config ...CORSConfig) HandlerFunc
func Logger ¶
func Logger() HandlerFunc
func Recovery ¶ added in v0.1.1
func Recovery() HandlerFunc
type RouterGroup ¶ added in v0.1.1
type RouterGroup struct {
// contains filtered or unexported fields
}
func (*RouterGroup) DELETE ¶ added in v0.1.1
func (rg *RouterGroup) DELETE(path string, handler HandlerFunc)
func (*RouterGroup) GET ¶ added in v0.1.1
func (rg *RouterGroup) GET(path string, handler HandlerFunc)
func (*RouterGroup) Group ¶ added in v0.1.1
func (rg *RouterGroup) Group(prefix string, middlewares ...HandlerFunc) *RouterGroup
func (*RouterGroup) HEAD ¶ added in v0.3.0
func (rg *RouterGroup) HEAD(path string, handler HandlerFunc)
func (*RouterGroup) PATCH ¶ added in v0.3.0
func (rg *RouterGroup) PATCH(path string, handler HandlerFunc)
func (*RouterGroup) POST ¶ added in v0.1.1
func (rg *RouterGroup) POST(path string, handler HandlerFunc)
func (*RouterGroup) PUT ¶ added in v0.1.1
func (rg *RouterGroup) PUT(path string, handler HandlerFunc)
func (*RouterGroup) SSE ¶ added in v0.2.16
func (rg *RouterGroup) SSE(relativePath string, handler SSEHandlerFunc)
SSE registers a Server-Sent Events handler at the given path. The response is kept open and events are pushed to the client until it disconnects. Group middlewares run before the SSE stream is opened.
func (*RouterGroup) Static ¶ added in v0.1.2
func (rg *RouterGroup) Static(relativePath string, root string)
Serve Static files
func (*RouterGroup) Use ¶ added in v0.1.1
func (rg *RouterGroup) Use(middlewares ...HandlerFunc)
func (*RouterGroup) WS ¶ added in v0.2.16
func (rg *RouterGroup) WS(relativePath string, handler WSHandlerFunc)
WS registers a WebSocket handler at the given path. Group middlewares (auth, rate limiting, etc.) run during the HTTP upgrade phase. If any middleware aborts the request, the upgrade is cancelled.
type SSEContext ¶ added in v0.2.16
type SSEContext struct {
Writer http.ResponseWriter
Keys map[string]any
Params httprouter.Params
Request *http.Request
// contains filtered or unexported fields
}
SSEContext wraps an active SSE connection with framework utilities. Use Send() to push events and Done() to detect client disconnection.
func (*SSEContext) Done ¶ added in v0.2.16
func (sc *SSEContext) Done() <-chan struct{}
Done returns a channel that is closed when the client disconnects. Use this to stop your event loop cleanly.
for {
select {
case <-c.Done():
return
default:
c.Send("ping", vodka.M{"ts": time.Now()})
time.Sleep(time.Second)
}
}
func (*SSEContext) Get ¶ added in v0.2.16
func (sc *SSEContext) Get(key string) (value any, exists bool)
Get retrieves a value previously stored via Set.
func (*SSEContext) IP ¶ added in v0.2.16
func (sc *SSEContext) IP() string
IP returns the remote address of the client.
func (*SSEContext) Param ¶ added in v0.2.16
func (sc *SSEContext) Param(key string) string
Param returns a URL path parameter by name.
func (*SSEContext) Query ¶ added in v0.2.16
func (sc *SSEContext) Query(key string) string
Query returns a URL query parameter by name.
func (*SSEContext) Send ¶ added in v0.2.16
func (sc *SSEContext) Send(event string, data any) error
Send pushes a named event with JSON-encoded data to the client. Returns an error if the connection is no longer writable.
c.Send("update", vodka.M{"value": 42})
func (*SSEContext) SendComment ¶ added in v0.2.16
func (sc *SSEContext) SendComment(comment string) error
SendComment writes an SSE comment line, useful as a keep-alive ping.
func (*SSEContext) SendData ¶ added in v0.2.16
func (sc *SSEContext) SendData(data any) error
SendData pushes data without a named event (browsers receive it as a "message" event).
func (*SSEContext) Set ¶ added in v0.2.16
func (sc *SSEContext) Set(key string, value any)
Set stores a value in the context by key.
type SSEHandlerFunc ¶ added in v0.2.16
type SSEHandlerFunc func(*SSEContext)
SSEHandlerFunc is the handler signature for Server-Sent Events connections.
type VodkaError ¶ added in v0.2.10
Custom error type
type WSConfig ¶ added in v0.2.16
type WSConfig struct {
ReadBufferSize int
WriteBufferSize int
HandshakeTimeout time.Duration
// CheckOrigin returns true to allow the connection. Defaults to allowing all origins.
CheckOrigin func(r *http.Request) bool
}
WSConfig holds configuration for the WebSocket upgrader.
func DefaultWSConfig ¶ added in v0.2.16
func DefaultWSConfig() *WSConfig
DefaultWSConfig returns a WSConfig with sensible defaults. By default only same-origin requests are allowed. Use engine.AllowWSOrigins() to permit others.
type WSContext ¶ added in v0.2.16
type WSContext struct {
Conn *websocket.Conn
Keys map[string]any
Params httprouter.Params
Request *http.Request
}
WSContext wraps a live WebSocket connection with framework utilities. URL params, query values, and keys set by HTTP middlewares are all accessible here.
func (*WSContext) Close ¶ added in v0.2.16
Close sends a normal closure message and closes the connection gracefully.
func (*WSContext) Param ¶ added in v0.2.16
Param returns a URL path parameter by name (e.g. /ws/:room → wc.Param("room")).
func (*WSContext) ReadJSON ¶ added in v0.2.16
ReadJSON reads the next message and decodes it as JSON into v.
func (*WSContext) ReadMessage ¶ added in v0.2.16
ReadMessage reads the next message from the connection. messageType is websocket.TextMessage or websocket.BinaryMessage.
func (*WSContext) Set ¶ added in v0.2.16
Set stores a value in the context by key, shared across the connection lifecycle.
type WSHandlerFunc ¶ added in v0.2.16
type WSHandlerFunc func(*WSContext)
WSHandlerFunc is the handler signature for WebSocket connections.

