Documentation
¶
Index ¶
- func DefaultFuncMap() template.FuncMap
- func Name(name, pattern string)
- func ResetNamedRoutes()
- func Route(name string, params ...string) string
- type ResourceController
- type RouteGroup
- func (g *RouteGroup) APIResource(path string, ctrl ResourceController)
- func (g *RouteGroup) Delete(path string, handlers ...gin.HandlerFunc)
- func (g *RouteGroup) Get(path string, handlers ...gin.HandlerFunc)
- func (g *RouteGroup) Group(prefix string, handlers ...gin.HandlerFunc) *RouteGroup
- func (g *RouteGroup) Options(path string, handlers ...gin.HandlerFunc)
- func (g *RouteGroup) Patch(path string, handlers ...gin.HandlerFunc)
- func (g *RouteGroup) Post(path string, handlers ...gin.HandlerFunc)
- func (g *RouteGroup) Put(path string, handlers ...gin.HandlerFunc)
- func (g *RouteGroup) Resource(path string, ctrl ResourceController)
- func (g *RouteGroup) Use(middleware ...gin.HandlerFunc)
- type Router
- func (r *Router) APIResource(path string, ctrl ResourceController)
- func (r *Router) Delete(path string, handlers ...gin.HandlerFunc)
- func (r *Router) DeprecatedVersion(version, sunsetDate string) *RouteGroup
- func (r *Router) Engine() *gin.Engine
- func (r *Router) Get(path string, handlers ...gin.HandlerFunc)
- func (r *Router) Group(prefix string, handlers ...gin.HandlerFunc) *RouteGroup
- func (r *Router) LoadTemplates(dir string)
- func (r *Router) Options(path string, handlers ...gin.HandlerFunc)
- func (r *Router) Patch(path string, handlers ...gin.HandlerFunc)
- func (r *Router) Post(path string, handlers ...gin.HandlerFunc)
- func (r *Router) Put(path string, handlers ...gin.HandlerFunc)
- func (r *Router) Resource(path string, ctrl ResourceController)
- func (r *Router) Run(addr string) error
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Router) SetFuncMap(funcMap template.FuncMap)
- func (r *Router) Static(urlPath, dirPath string)
- func (r *Router) StaticFile(urlPath, filePath string)
- func (r *Router) Use(middleware ...gin.HandlerFunc)
- func (r *Router) Version(version string) *RouteGroup
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultFuncMap ¶
DefaultFuncMap returns the template function map with framework helpers.
func ResetNamedRoutes ¶
func ResetNamedRoutes()
ResetNamedRoutes clears all named routes. Used in tests only.
Types ¶
type ResourceController ¶
type ResourceController interface {
Index(c *gin.Context) // GET /resource
Create(c *gin.Context) // GET /resource/create (SSR form)
Store(c *gin.Context) // POST /resource
Show(c *gin.Context) // GET /resource/:id
Edit(c *gin.Context) // GET /resource/:id/edit (SSR form)
Update(c *gin.Context) // PUT /resource/:id
Destroy(c *gin.Context) // DELETE /resource/:id
}
ResourceController defines the interface for RESTful controllers. Implement all 7 methods for full CRUD with form routes, or use APIResource to skip Create/Edit form routes.
type RouteGroup ¶
type RouteGroup struct {
// contains filtered or unexported fields
}
RouteGroup wraps a Gin router group for sub-route registration.
func (*RouteGroup) APIResource ¶
func (g *RouteGroup) APIResource(path string, ctrl ResourceController)
APIResource registers 5 RESTful routes (no Create/Edit form routes) on the group.
func (*RouteGroup) Delete ¶
func (g *RouteGroup) Delete(path string, handlers ...gin.HandlerFunc)
Delete registers a DELETE route in the group.
func (*RouteGroup) Get ¶
func (g *RouteGroup) Get(path string, handlers ...gin.HandlerFunc)
Get registers a GET route in the group.
func (*RouteGroup) Group ¶
func (g *RouteGroup) Group(prefix string, handlers ...gin.HandlerFunc) *RouteGroup
Group creates a nested sub-group with a shared prefix and optional middleware.
func (*RouteGroup) Options ¶
func (g *RouteGroup) Options(path string, handlers ...gin.HandlerFunc)
Options registers an OPTIONS route in the group.
func (*RouteGroup) Patch ¶
func (g *RouteGroup) Patch(path string, handlers ...gin.HandlerFunc)
Patch registers a PATCH route in the group.
func (*RouteGroup) Post ¶
func (g *RouteGroup) Post(path string, handlers ...gin.HandlerFunc)
Post registers a POST route in the group.
func (*RouteGroup) Put ¶
func (g *RouteGroup) Put(path string, handlers ...gin.HandlerFunc)
Put registers a PUT route in the group.
func (*RouteGroup) Resource ¶
func (g *RouteGroup) Resource(path string, ctrl ResourceController)
Resource registers all 7 RESTful routes for a controller on the group.
func (*RouteGroup) Use ¶
func (g *RouteGroup) Use(middleware ...gin.HandlerFunc)
Use adds middleware to the group.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router wraps the Gin engine and provides framework-level route registration.
func (*Router) APIResource ¶
func (r *Router) APIResource(path string, ctrl ResourceController)
APIResource registers 5 RESTful routes (no Create/Edit form routes) on the router.
func (*Router) Delete ¶
func (r *Router) Delete(path string, handlers ...gin.HandlerFunc)
Delete registers a DELETE route.
func (*Router) DeprecatedVersion ¶
func (r *Router) DeprecatedVersion(version, sunsetDate string) *RouteGroup
DeprecatedVersion creates a versioned route group (like Version) but injects middleware that adds deprecation headers to every response:
- Sunset: {sunsetDate} — RFC 8594 sunset date in HTTP-date format
- X-API-Deprecated: true — simple boolean signal for clients/monitoring
Example:
v1 := r.DeprecatedVersion("v1", "Sat, 01 Jun 2026 00:00:00 GMT")
v1.Get("/users", listUsersV1)
func (*Router) Get ¶
func (r *Router) Get(path string, handlers ...gin.HandlerFunc)
Get registers a GET route.
func (*Router) Group ¶
func (r *Router) Group(prefix string, handlers ...gin.HandlerFunc) *RouteGroup
Group creates a new route group with a shared prefix and optional middleware.
func (*Router) LoadTemplates ¶
LoadTemplates recursively loads all .html templates from the given directory.
func (*Router) Options ¶
func (r *Router) Options(path string, handlers ...gin.HandlerFunc)
Options registers an OPTIONS route.
func (*Router) Patch ¶
func (r *Router) Patch(path string, handlers ...gin.HandlerFunc)
Patch registers a PATCH route.
func (*Router) Post ¶
func (r *Router) Post(path string, handlers ...gin.HandlerFunc)
Post registers a POST route.
func (*Router) Put ¶
func (r *Router) Put(path string, handlers ...gin.HandlerFunc)
Put registers a PUT route.
func (*Router) Resource ¶
func (r *Router) Resource(path string, ctrl ResourceController)
Resource registers all 7 RESTful routes for a controller on the router.
func (*Router) ServeHTTP ¶
func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP implements http.Handler, delegating to the Gin engine.
func (*Router) SetFuncMap ¶
SetFuncMap sets the template function map on the Gin engine. Must be called before LoadTemplates.
func (*Router) StaticFile ¶
StaticFile serves a single file at the given URL path.
func (*Router) Use ¶
func (r *Router) Use(middleware ...gin.HandlerFunc)
Use adds global middleware to the router.
func (*Router) Version ¶
func (r *Router) Version(version string) *RouteGroup
Version creates a route group prefixed with /api/{version}. The returned RouteGroup supports all existing route registration methods.
Example:
v1 := r.Version("v1") // prefix: /api/v1
v1.Get("/users", listUsers)
v1.APIResource("/posts", &PostController{})