Documentation
¶
Index ¶
- func Error(w http.ResponseWriter, status int, message string) error
- func JSON(w http.ResponseWriter, status int, data any) error
- func Success(w http.ResponseWriter, status int, data any) error
- func URLParam(r *http.Request, key string) string
- type Middleware
- type Router
- func (r *Router) Delete(pattern string, h http.HandlerFunc)
- func (r *Router) Get(pattern string, h http.HandlerFunc)
- func (r *Router) Group(fn func(sub *Router))
- func (r *Router) Handler() http.Handler
- func (r *Router) Head(pattern string, h http.HandlerFunc)
- func (r *Router) Options(pattern string, h http.HandlerFunc)
- func (r *Router) Patch(pattern string, h http.HandlerFunc)
- func (r *Router) Post(pattern string, h http.HandlerFunc)
- func (r *Router) Put(pattern string, h http.HandlerFunc)
- func (r *Router) Route(prefix string, fn func(sub *Router))
- func (r *Router) Routes() []struct{ ... }
- func (r *Router) Serve(addr string) error
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Router) Shutdown(ctx context.Context) error
- func (r *Router) Use(mw ...Middleware)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Error ¶
func Error(w http.ResponseWriter, status int, message string) error
Error writes a JSON error envelope: {"error": "..."}.
func JSON ¶
func JSON(w http.ResponseWriter, status int, data any) error
JSON writes a JSON body with the given status code. Note: WriteHeader is called before Encode, so once JSON starts writing you can no longer change the status. Validate/marshal-check earlier if that matters for a given handler.
Types ¶
type Middleware ¶
Middleware is the standard net/http middleware signature. It's an alias (not a new type) so it's interchangeable with plain func(http.Handler) http.Handler everywhere.
func CORS ¶
func CORS(origins ...string) Middleware
CORS returns a permissive CORS middleware. Pass a single origin to restrict it; default is "*".
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router wraps a go-chi mux and exposes a Vormia-friendly API. The concrete *Router will structurally satisfy the Router interface that vormia-go defines later — no framework import required.
func (*Router) Group ¶
Group runs fn on an inline sub-router that inherits middleware. No path prefix — use this to apply middleware to a set of routes.
func (*Router) Routes ¶ added in v1.1.0
Routes returns every registered method+pattern pair, via chi.Walk. The return type matches vormia-go's contract.RouteInfo alias (anonymous struct) without importing the framework.
func (*Router) ServeHTTP ¶
func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP makes *Router itself an http.Handler (handy for tests and for embedding behind other handlers).
func (*Router) Use ¶
func (r *Router) Use(mw ...Middleware)
Use registers global middleware. Must be called BEFORE routes are added.