Documentation
¶
Index ¶
- Variables
- func NotFoundHTMLOrJSON(notFoundHTMLFile string, jsonMessage string) http.HandlerFunc
- func ParseDTO[T any](ctx *Context) (T, error)
- func RegisterGeneratedControllerMetadata(controllerPtr any, meta ControllerMetadata)
- func ServePage(publicDir, pageFile string) http.HandlerFunc
- func SetDefaultValidator(v Validator)
- func Validate(dto any) error
- func WebAPIHandler(web http.Handler, api http.Handler, opts HybridOptions) http.Handler
- type App
- type Container
- type Context
- func (c *Context) BadRequest(message string) error
- func (c *Context) BindJSON(dto any) error
- func (c *Context) Conflict(message string) error
- func (c *Context) Created(data any) error
- func (c *Context) Error(status int, message string) error
- func (c *Context) Forbidden(message string) error
- func (c *Context) Get(key string) (any, bool)
- func (c *Context) InternalError(message string) error
- func (c *Context) JSON(status int, body any) error
- func (c *Context) NoContent() error
- func (c *Context) NotFound(message string) error
- func (c *Context) OK(data any) error
- func (c *Context) Param(name string) string
- func (c *Context) Set(key string, value any)
- func (c *Context) Success(status int, data any) error
- func (c *Context) Text(status int, value string) error
- func (c *Context) Unauthorized(message string) error
- type Controller
- type ControllerMetadata
- type DecoratedController
- type GoPlaygroundValidator
- type HTTPError
- type HandlerFunc
- type HybridOptions
- type Middleware
- type Module
- type RouteGroup
- func (g *RouteGroup) DELETE(path string, handler HandlerFunc, middleware ...Middleware)
- func (g *RouteGroup) GET(path string, handler HandlerFunc, middleware ...Middleware)
- func (g *RouteGroup) Group(prefix string, middleware ...Middleware) *RouteGroup
- func (g *RouteGroup) OPTIONS(path string, handler HandlerFunc, middleware ...Middleware)
- func (g *RouteGroup) PATCH(path string, handler HandlerFunc, middleware ...Middleware)
- func (g *RouteGroup) POST(path string, handler HandlerFunc, middleware ...Middleware)
- func (g *RouteGroup) PUT(path string, handler HandlerFunc, middleware ...Middleware)
- type RouteMetadata
- func DELETE(path, handler string, middleware ...Middleware) RouteMetadata
- func GET(path, handler string, middleware ...Middleware) RouteMetadata
- func OPTIONS(path, handler string, middleware ...Middleware) RouteMetadata
- func PATCH(path, handler string, middleware ...Middleware) RouteMetadata
- func POST(path, handler string, middleware ...Middleware) RouteMetadata
- func PUT(path, handler string, middleware ...Middleware) RouteMetadata
- type Router
- func (r *Router) DELETE(path string, handler HandlerFunc, middleware ...Middleware)
- func (r *Router) GET(path string, handler HandlerFunc, middleware ...Middleware)
- func (r *Router) Group(prefix string, middleware ...Middleware) *RouteGroup
- func (r *Router) OPTIONS(path string, handler HandlerFunc, middleware ...Middleware)
- func (r *Router) PATCH(path string, handler HandlerFunc, middleware ...Middleware)
- func (r *Router) POST(path string, handler HandlerFunc, middleware ...Middleware)
- func (r *Router) PUT(path string, handler HandlerFunc, middleware ...Middleware)
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Router) SetValidator(v Validator)
- func (r *Router) Use(middleware ...Middleware)
- func (r *Router) Validator() Validator
- type ValidationError
- type ValidationErrors
- type Validator
- type ValidatorFunc
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("route not found")
var ErrValidation = errors.New("validation failed")
Functions ¶
func NotFoundHTMLOrJSON ¶ added in v1.0.1
func NotFoundHTMLOrJSON(notFoundHTMLFile string, jsonMessage string) http.HandlerFunc
NotFoundHTMLOrJSON serves an HTML 404 page for browser requests and JSON for APIs.
func RegisterGeneratedControllerMetadata ¶
func RegisterGeneratedControllerMetadata(controllerPtr any, meta ControllerMetadata)
RegisterGeneratedControllerMetadata is used by generated code.
func ServePage ¶ added in v1.0.1
func ServePage(publicDir, pageFile string) http.HandlerFunc
ServePage returns a handler that serves a single static page from publicDir.
func SetDefaultValidator ¶
func SetDefaultValidator(v Validator)
SetDefaultValidator sets the process-wide default validator used by Validate and new routers.
func WebAPIHandler ¶ added in v1.0.1
WebAPIHandler composes web and api handlers, reducing manual path-switch boilerplate.
Types ¶
type App ¶
func (*App) Handler ¶
Handler exposes the application router as an http.Handler. This makes it easy to mount in Gin/Echo/Fiber adapter wrappers.
func (*App) SetValidator ¶
SetValidator overrides the app/router validator for request DTO validation.
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
func NewContainer ¶
func NewContainer() *Container
func (*Container) MustResolve ¶
type Context ¶
type Context struct {
ResponseWriter http.ResponseWriter
Request *http.Request
Params map[string]string
Values map[string]any
// contains filtered or unexported fields
}
Context carries request/response helpers for handlers and middleware.
func (*Context) BadRequest ¶ added in v1.0.1
func (*Context) Error ¶ added in v1.0.1
Error returns a standard error envelope: {"success": false, "error": ...}.
func (*Context) InternalError ¶ added in v1.0.1
func (*Context) Success ¶ added in v1.0.1
Success returns a standard success envelope: {"success": true, "data": ...}.
func (*Context) Unauthorized ¶ added in v1.0.1
type Controller ¶
type Controller interface {
RegisterRoutes(*RouteGroup)
}
type ControllerMetadata ¶
type ControllerMetadata struct {
Prefix string
Middleware []Middleware
Routes []RouteMetadata
}
ControllerMetadata is decorator-like route metadata for a controller.
type DecoratedController ¶
type DecoratedController interface {
ControllerMetadata() ControllerMetadata
}
DecoratedController declares controller metadata for auto route binding.
type GoPlaygroundValidator ¶
type GoPlaygroundValidator struct {
// contains filtered or unexported fields
}
GoPlaygroundValidator uses github.com/go-playground/validator/v10.
func NewGoPlaygroundValidator ¶
func NewGoPlaygroundValidator() *GoPlaygroundValidator
func (*GoPlaygroundValidator) Validate ¶
func (g *GoPlaygroundValidator) Validate(dto any) error
type HTTPError ¶
func NewHTTPError ¶
type HandlerFunc ¶
type HybridOptions ¶ added in v1.0.1
type HybridOptions struct {
WebExactPaths []string
WebPathPrefixes []string
TreatSingleSegmentGETAsWeb bool
}
HybridOptions controls how WebAPIHandler routes traffic to web or api handlers.
type Middleware ¶
type Middleware func(HandlerFunc) HandlerFunc
func AdaptHTTPMiddleware ¶ added in v1.0.1
func AdaptHTTPMiddleware(httpMW func(http.Handler) http.Handler) Middleware
AdaptHTTPMiddleware adapts a standard net/http middleware into gocontroller middleware.
func RequestLogger ¶ added in v1.0.1
func RequestLogger() Middleware
RequestLogger logs method, path, status time around each request.
type Module ¶
type Module struct {
Name string
Prefix string
Providers []any
Controllers []any
Imports []*Module
Middleware []Middleware
}
Module models a NestJS-like module graph.
type RouteGroup ¶
type RouteGroup struct {
// contains filtered or unexported fields
}
func (*RouteGroup) DELETE ¶
func (g *RouteGroup) DELETE(path string, handler HandlerFunc, middleware ...Middleware)
func (*RouteGroup) GET ¶
func (g *RouteGroup) GET(path string, handler HandlerFunc, middleware ...Middleware)
func (*RouteGroup) Group ¶
func (g *RouteGroup) Group(prefix string, middleware ...Middleware) *RouteGroup
func (*RouteGroup) OPTIONS ¶
func (g *RouteGroup) OPTIONS(path string, handler HandlerFunc, middleware ...Middleware)
func (*RouteGroup) PATCH ¶
func (g *RouteGroup) PATCH(path string, handler HandlerFunc, middleware ...Middleware)
func (*RouteGroup) POST ¶
func (g *RouteGroup) POST(path string, handler HandlerFunc, middleware ...Middleware)
func (*RouteGroup) PUT ¶
func (g *RouteGroup) PUT(path string, handler HandlerFunc, middleware ...Middleware)
type RouteMetadata ¶
type RouteMetadata struct {
Method string
Path string
Handler string
Middleware []Middleware
}
RouteMetadata describes a single route in a controller.
func DELETE ¶
func DELETE(path, handler string, middleware ...Middleware) RouteMetadata
func GET ¶
func GET(path, handler string, middleware ...Middleware) RouteMetadata
func OPTIONS ¶
func OPTIONS(path, handler string, middleware ...Middleware) RouteMetadata
func PATCH ¶
func PATCH(path, handler string, middleware ...Middleware) RouteMetadata
func POST ¶
func POST(path, handler string, middleware ...Middleware) RouteMetadata
func PUT ¶
func PUT(path, handler string, middleware ...Middleware) RouteMetadata
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router provides method-based routing and middleware composition.
func (*Router) DELETE ¶
func (r *Router) DELETE(path string, handler HandlerFunc, middleware ...Middleware)
func (*Router) GET ¶
func (r *Router) GET(path string, handler HandlerFunc, middleware ...Middleware)
func (*Router) Group ¶
func (r *Router) Group(prefix string, middleware ...Middleware) *RouteGroup
func (*Router) OPTIONS ¶
func (r *Router) OPTIONS(path string, handler HandlerFunc, middleware ...Middleware)
func (*Router) PATCH ¶
func (r *Router) PATCH(path string, handler HandlerFunc, middleware ...Middleware)
func (*Router) POST ¶
func (r *Router) POST(path string, handler HandlerFunc, middleware ...Middleware)
func (*Router) PUT ¶
func (r *Router) PUT(path string, handler HandlerFunc, middleware ...Middleware)
func (*Router) SetValidator ¶
SetValidator overrides validation engine used by Context.BindJSON for this router.
func (*Router) Use ¶
func (r *Router) Use(middleware ...Middleware)
type ValidationError ¶
type ValidationErrors ¶
type ValidationErrors []ValidationError
func (ValidationErrors) Error ¶
func (ve ValidationErrors) Error() string
func (ValidationErrors) Unwrap ¶
func (ve ValidationErrors) Unwrap() error
type Validator ¶
Validator is a pluggable validation engine.
func DefaultValidator ¶
func DefaultValidator() Validator
DefaultValidator returns the process-wide default validator.
type ValidatorFunc ¶
ValidatorFunc adapts a function into a Validator.
func (ValidatorFunc) Validate ¶
func (f ValidatorFunc) Validate(v any) error