gocontroller

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package gocontroller wires providers and controllers into an existing router. It does not own the HTTP server, request context, or middleware runtime.

Index

Constants

View Source
const Version = "2.1.0"

Variables

This section is empty.

Functions

func Mount

func Mount(adapter Adapter, root *Module) error

Mount resolves constructors, composes route metadata, and registers the result on an existing router. Call it before serving requests. A native registration failure can leave earlier routes mounted; discard the router on any error.

Types

type Adapter

type Adapter interface {
	Register([]Route) error
}

Adapter registers a complete batch of routes on a host router. Implementations must validate all handler and middleware types before registering any routes. Routing, request execution, and errors remain the host framework's concern.

type Controller

type Controller interface {
	ControllerMetadata() ControllerMetadata
}

Controller declares routes using bound native framework handler methods. Implement this directly or generate it from @Controller and @Get comments.

type ControllerDeclaration added in v2.1.0

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

ControllerDeclaration describes a controller for gocontroller-gen. Configure declarations during package initialization, before mounting controllers.

func Controllers added in v2.1.0

func Controllers(prefix string) *ControllerDeclaration

Controllers declares a prefix for methods marked with var _ = name.GET(...).

func (*ControllerDeclaration) CONNECT added in v2.1.0

func (d *ControllerDeclaration) CONNECT(path string, middleware ...any) *RouteDeclaration

func (*ControllerDeclaration) DELETE added in v2.1.0

func (d *ControllerDeclaration) DELETE(path string, middleware ...any) *RouteDeclaration

func (*ControllerDeclaration) GET added in v2.1.0

func (d *ControllerDeclaration) GET(path string, middleware ...any) *RouteDeclaration

func (*ControllerDeclaration) HEAD added in v2.1.0

func (d *ControllerDeclaration) HEAD(path string, middleware ...any) *RouteDeclaration

func (*ControllerDeclaration) MustBind added in v2.1.0

func (d *ControllerDeclaration) MustBind(bindings ...Route) ControllerMetadata

MustBind is used by generated metadata. It binds native handlers without rerunning middleware factories. Stale bindings panic during startup.

func (*ControllerDeclaration) OPTIONS added in v2.1.0

func (d *ControllerDeclaration) OPTIONS(path string, middleware ...any) *RouteDeclaration

func (*ControllerDeclaration) PATCH added in v2.1.0

func (d *ControllerDeclaration) PATCH(path string, middleware ...any) *RouteDeclaration

func (*ControllerDeclaration) POST added in v2.1.0

func (d *ControllerDeclaration) POST(path string, middleware ...any) *RouteDeclaration

func (*ControllerDeclaration) PUT added in v2.1.0

func (d *ControllerDeclaration) PUT(path string, middleware ...any) *RouteDeclaration

func (*ControllerDeclaration) TRACE added in v2.1.0

func (d *ControllerDeclaration) TRACE(path string, middleware ...any) *RouteDeclaration

func (*ControllerDeclaration) Use added in v2.1.0

func (d *ControllerDeclaration) Use(middleware ...any) *ControllerDeclaration

func (*ControllerDeclaration) UseAfter added in v2.1.0

func (d *ControllerDeclaration) UseAfter(middleware ...any) *ControllerDeclaration

func (*ControllerDeclaration) UseBefore added in v2.1.0

func (d *ControllerDeclaration) UseBefore(middleware ...any) *ControllerDeclaration

type ControllerMetadata

type ControllerMetadata struct {
	Prefix     string
	Middleware []any
	Routes     []Route
}

type MiddlewareGroup added in v2.1.0

type MiddlewareGroup struct {
	Before []any
	After  []any
}

MiddlewareGroup places native middleware before or after the controller handler. After middleware follows the framework's continuation/error rules; it is not a response transformer or a guaranteed finally hook.

func UseAfter added in v2.1.0

func UseAfter(middleware ...any) MiddlewareGroup

func UseBefore added in v2.1.0

func UseBefore(middleware ...any) MiddlewareGroup

type Module

type Module struct {
	Name        string
	Prefix      string
	Providers   []any
	Controllers []any
	Imports     []*Module
	Middleware  []any
}

Module groups controllers and providers. Imported prefixes and middleware nest beneath their parent. Providers are shared singletons within one Mount.

type Route

type Route struct {
	Method     string
	Path       string
	Handler    any
	Middleware []any
}

Route carries native handlers and middleware. Their types are checked by the selected adapter at mount time, before any routes are registered.

func CONNECT

func CONNECT(path string, handler any, middleware ...any) Route

func DELETE

func DELETE(path string, handler any, middleware ...any) Route

func GET

func GET(path string, handler any, middleware ...any) Route
func HEAD(path string, handler any, middleware ...any) Route

func OPTIONS

func OPTIONS(path string, handler any, middleware ...any) Route

func PATCH

func PATCH(path string, handler any, middleware ...any) Route

func POST

func POST(path string, handler any, middleware ...any) Route

func PUT

func PUT(path string, handler any, middleware ...any) Route

func TRACE

func TRACE(path string, handler any, middleware ...any) Route

type RouteDeclaration added in v2.1.0

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

RouteDeclaration attaches routing information to the following method.

func (*RouteDeclaration) Use added in v2.1.0

func (r *RouteDeclaration) Use(middleware ...any) *RouteDeclaration

func (*RouteDeclaration) UseAfter added in v2.1.0

func (r *RouteDeclaration) UseAfter(middleware ...any) *RouteDeclaration

func (*RouteDeclaration) UseBefore added in v2.1.0

func (r *RouteDeclaration) UseBefore(middleware ...any) *RouteDeclaration

Jump to

Keyboard shortcuts

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