routegroup

package
v0.42.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package routegroup provides the App-level route group abstraction.

A RouteGroup clusters routes under a shared prefix, middleware stack, and optional access policy. Groups nest and compose with the existing router + middleware pipeline.

Basic usage:

api := app.Group("/api")
api.Use(authMiddleware)
api.Entity("orders", entityConfig)  // mounts at /api/orders

Nested groups:

v1 := app.Group("/api/v1")
v1.Entity("users", ...)
v2 := app.Group("/api/v2")
v2.Entity("users", ...)

Access policy:

admin := app.Group("/admin", routegroup.WithAccess(access.RequirePermission("admin:access")))
admin.Entity("settings", ...)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GroupOption

type GroupOption func(*RouteGroup)

GroupOption configures a RouteGroup.

func WithAccess

func WithAccess(mw router.Middleware) GroupOption

WithAccess applies an access-control middleware as the outermost group-scoped layer. Use it with access.RequirePermission or any similar gate. The middleware runs before any other group middleware and before the route handler.

func WithMCPNamespace

func WithMCPNamespace(ns string) GroupOption

WithMCPNamespace prefixes MCP tool names registered inside this group. E.g. WithMCPNamespace("admin") makes an entity "users" register MCP tools as "admin.users.list", "admin.users.get", etc.

func WithMiddleware

func WithMiddleware(mw ...router.Middleware) GroupOption

WithMiddleware adds group-scoped middleware to all routes in the group.

func WithOpenAPITag

func WithOpenAPITag(tag string) GroupOption

WithOpenAPITag sets the OpenAPI tag for all routes in this group. Entity routes that would normally be tagged by entity name instead receive this group-level tag, keeping the spec organized.

type RouteGroup

type RouteGroup struct {
	// contains filtered or unexported fields
}

RouteGroup clusters routes under a shared prefix, middleware stack, and optional access policy. It delegates to the underlying core/router.Group for prefix and middleware chaining while adding App-level concerns: OpenAPI tagging and MCP tool namespacing.

RouteGroup does NOT own entity registration — that stays on App. The group provides the router surface (Handle/Get/Post/...) and the metadata (prefix, OpenAPI tag, MCP namespace) that App.GroupEntity reads when mounting an entity into a group.

func New

func New(parent *router.Router, prefix string, opts ...GroupOption) *RouteGroup

New creates a new RouteGroup on the given router with the given prefix. The group inherits parent middleware; any GroupOption adds to it.

func (*RouteGroup) Delete

func (g *RouteGroup) Delete(pattern string, handler http.Handler)

Delete registers a DELETE handler within the group.

func (*RouteGroup) Get

func (g *RouteGroup) Get(pattern string, handler http.Handler)

Get registers a GET handler within the group.

func (*RouteGroup) Group

func (g *RouteGroup) Group(prefix string, opts ...GroupOption) *RouteGroup

Group creates a nested sub-group. The child inherits this group's prefix and middleware; its own options add to them.

func (*RouteGroup) Handle

func (g *RouteGroup) Handle(method, pattern string, handler http.Handler)

Handle registers a handler for the given method and pattern within the group's prefix.

func (*RouteGroup) MCPNamespace

func (g *RouteGroup) MCPNamespace() string

MCPNamespace returns the configured MCP namespace, or empty string.

func (*RouteGroup) MCPToolName

func (g *RouteGroup) MCPToolName(entityName, action string) string

MCPToolName builds the full MCP tool name for an entity in this group. If a namespace is set, returns "<namespace>.<entity>.<action>". Otherwise returns the default "<entity>.<action>".

func (*RouteGroup) OpenAPITag

func (g *RouteGroup) OpenAPITag() string

OpenAPITag returns the configured OpenAPI tag, or empty string.

func (*RouteGroup) Patch

func (g *RouteGroup) Patch(pattern string, handler http.Handler)

Patch registers a PATCH handler within the group.

func (*RouteGroup) Post

func (g *RouteGroup) Post(pattern string, handler http.Handler)

Post registers a POST handler within the group.

func (*RouteGroup) Prefix

func (g *RouteGroup) Prefix() string

Prefix returns the full URL prefix for this group.

func (*RouteGroup) Put

func (g *RouteGroup) Put(pattern string, handler http.Handler)

Put registers a PUT handler within the group.

func (*RouteGroup) Router

func (g *RouteGroup) Router() *router.Router

Router returns the underlying sub-router. Use this when you need to pass the group's router to external registrars (CRUD, Mountable, etc.).

func (*RouteGroup) Use

func (g *RouteGroup) Use(mw ...router.Middleware)

Use adds middleware to the group's sub-router.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL