mbr

package module
v0.9.2-rc Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 15 Imported by: 3

README

mitoteam/mbr - Methods-Based Router

Reference GitHub code size GitHub

GitHub Version GitHub Release GitHub commit activity

Simple net/http stdlib-based router with:

  • direct method binding
  • reverse urls builder

Description, examples and docs are coming, please stand by.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dump

func Dump()

func Handler

func Handler(rootController Controller) http.Handler

func Url

func Url(routeRef any, args ...any) (r string)

func UrlE

func UrlE(routeRef any, args ...any) (r string, err error)

Types

type Controller

type Controller interface {
	WithMiddlewareList

	ParentControllers() []Controller
	SetParentControllers(parents []Controller)
}

type ControllerBase

type ControllerBase struct {
	WithMiddlewareListBase
	// contains filtered or unexported fields
}

func (*ControllerBase) ParentControllers

func (ctrl *ControllerBase) ParentControllers() []Controller

func (*ControllerBase) SetParentControllers

func (ctrl *ControllerBase) SetParentControllers(parents []Controller)

type MbrContext

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

func Context

func Context(r *http.Request) *MbrContext

gets MbrContext from request's http.Context

func (*MbrContext) Error

func (ctx *MbrContext) Error(error string, args ...any)

Issues http error "500 Internal server error"

func (*MbrContext) ErrorWithCode

func (ctx *MbrContext) ErrorWithCode(code int, error string, args ...any)

Issues http error with given code

func (*MbrContext) Get

func (ctx *MbrContext) Get(key string) any

func (*MbrContext) GetOk

func (ctx *MbrContext) GetOk(key string) (any, bool)

func (*MbrContext) IsRedirect

func (ctx *MbrContext) IsRedirect() bool

func (*MbrContext) Redirect

func (ctx *MbrContext) Redirect(code int, url string)

Helper to issue https redirects

func (*MbrContext) RedirectRoute

func (ctx *MbrContext) RedirectRoute(code int, routeRef any, args ...any)

Helper to issue https redirects. routeRef and args passed to UrlE()

func (*MbrContext) Request

func (ctx *MbrContext) Request() *http.Request

func (*MbrContext) Route

func (ctx *MbrContext) Route() *Route

func (*MbrContext) Set

func (ctx *MbrContext) Set(key string, value any) *MbrContext

func (*MbrContext) Writer

func (ctx *MbrContext) Writer() http.ResponseWriter

type Middleware

type Middleware func(next http.Handler) http.Handler

standard net/http middleware alias

type MiddlewareList

type MiddlewareList []Middleware

type Route

type Route struct {
	WithMiddlewareListBase

	PathPattern     string
	Method          string // empty = any, or space-separated methods list. examples "GET", "POST GET", "HEAD, GET"
	HandleF         RouterHandleFunc
	ChildController Controller
	StaticFS        fs.FS
	FileFromFS      string
	// contains filtered or unexported fields
}

func (*Route) FullPath

func (route *Route) FullPath() string

func (*Route) MethodList

func (route *Route) MethodList() []string

func (*Route) Name

func (route *Route) Name() string

type RouterHandleFunc

type RouterHandleFunc func(ctx *MbrContext) any

type WithMiddlewareList

type WithMiddlewareList interface {
	With(middleware Middleware)
	Middlewares() MiddlewareList
	ApplyMiddlewares(http.Handler) http.Handler
}

type WithMiddlewareListBase

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

func (*WithMiddlewareListBase) ApplyMiddlewares

func (o *WithMiddlewareListBase) ApplyMiddlewares(handler http.Handler) http.Handler

func (*WithMiddlewareListBase) Middlewares

func (o *WithMiddlewareListBase) Middlewares() MiddlewareList

func (*WithMiddlewareListBase) With

func (o *WithMiddlewareListBase) With(middleware Middleware)

Jump to

Keyboard shortcuts

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