route

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2025 License: GPL-3.0 Imports: 7 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilRouter     = errors.New("router cannot be nil")
	ErrNilMiddleware = "%s: middleware at index %d cannot be nil"
	ErrEmptyPattern  = errors.New("pattern cannot be empty")
)

Functions

func ChainHandlers added in v0.5.10

func ChainHandlers(
	lastHandler http.Handler,
	handlers ...func(http.Handler) http.Handler,
) http.Handler

ChainHandlers chains the handlers

func SplitPattern added in v0.7.25

func SplitPattern(pattern string) (string, string, error)

SplitPattern returns the method and the path from the pattern

Types

type Logger added in v0.4.0

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

Logger is the logger for router

func NewLogger added in v0.4.0

func NewLogger(header string, modeLogger gologgermode.Logger) (*Logger, error)

NewLogger is the logger for the router

func (*Logger) RegisterRoute added in v0.4.0

func (l *Logger) RegisterRoute(fullPath, pattern string)

RegisterRoute registers a route

func (*Logger) RegisterRouteGroup added in v0.4.0

func (l *Logger) RegisterRouteGroup(fullPath, pattern string)

RegisterRouteGroup registers a route group

type Router added in v0.2.2

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

Router is the route group struct

func NewBaseRouter added in v0.4.2

func NewBaseRouter(
	mode *goflagsmode.Flag,
	logger *Logger,
	middlewares ...func(next http.Handler) http.Handler,
) (*Router, error)

NewBaseRouter creates a new base router

func NewGroup

func NewGroup(
	baseRouter *Router,
	pattern string,
	middlewares ...func(next http.Handler) http.Handler,
) (*Router, error)

NewGroup creates a new router group

func NewRouter added in v0.2.2

func NewRouter(
	pattern string,
	mode *goflagsmode.Flag,
	logger *Logger,
	middlewares ...func(next http.Handler) http.Handler,
) (*Router, error)

NewRouter creates a new router

func (*Router) ExactHandleFunc added in v0.7.24

func (r *Router) ExactHandleFunc(
	pattern string,
	handler http.HandlerFunc,
	middlewares ...func(http.Handler) http.Handler,
)

ExactHandleFunc registers a new route with a path, the handler function and the middlewares

func (*Router) FullPath added in v0.7.22

func (r *Router) FullPath() string

FullPath returns the full path

func (*Router) GetMiddlewares added in v0.7.10

func (r *Router) GetMiddlewares() *[]func(http.Handler) http.Handler

GetMiddlewares returns the middlewares

func (*Router) HandleFunc added in v0.2.2

func (r *Router) HandleFunc(
	pattern string,
	handler http.HandlerFunc,
	middlewares ...func(http.Handler) http.Handler,
)

HandleFunc registers a new route with a path, the handler function and the middlewares

func (*Router) Handler added in v0.2.3

func (r *Router) Handler() http.Handler

Handler returns the first handler

func (*Router) Method added in v0.7.25

func (r *Router) Method() string

Method returns the method

func (*Router) Mux added in v0.5.10

func (r *Router) Mux() *http.ServeMux

Mux returns the multiplexer

func (*Router) NewGroup added in v0.4.2

func (r *Router) NewGroup(
	pattern string,
	middlewares ...func(next http.Handler) http.Handler,
) *Router

NewGroup creates a new router group with a path

func (*Router) Pattern added in v0.7.25

func (r *Router) Pattern() string

Pattern returns the pattern

func (*Router) RegisterExactRoute added in v0.7.24

func (r *Router) RegisterExactRoute(
	pattern string,
	handler http.HandlerFunc,
	middlewares ...func(http.Handler) http.Handler,
)

RegisterExactRoute registers a new route with a path, the handler function and the middlewares. This matches the exact path

func (*Router) RegisterGroup added in v0.4.2

func (r *Router) RegisterGroup(router *Router)

RegisterGroup registers a new router group with a path and a router

func (*Router) RegisterHandler added in v0.2.2

func (r *Router) RegisterHandler(pattern string, handler http.Handler)

RegisterHandler registers a new route group with a path and a handler function

func (*Router) RegisterRoute added in v0.2.2

func (r *Router) RegisterRoute(
	pattern string,
	handler http.HandlerFunc,
	middlewares ...func(http.Handler) http.Handler,
)

RegisterRoute registers a new route with a path, the handler function and the middlewares. This does not match the exact path

func (*Router) RelativePath added in v0.7.22

func (r *Router) RelativePath() string

RelativePath returns the relative path

type RouterWrapper added in v0.2.2

type RouterWrapper interface {
	Handler() http.Handler
	Mux() *http.ServeMux
	GetMiddlewares() *[]func(http.Handler) http.Handler
	HandleFunc(
		pattern string,
		handler http.HandlerFunc,
		middlewares ...func(next http.Handler) http.Handler,
	)
	ExactHandleFunc(
		pattern string,
		handler http.HandlerFunc,
		middlewares ...func(next http.Handler) http.Handler,
	)
	RegisterRoute(
		pattern string,
		handler http.HandlerFunc,
		middlewares ...func(next http.Handler) http.Handler,
	)
	RegisterExactRoute(
		pattern string,
		handler http.HandlerFunc,
		middlewares ...func(next http.Handler) http.Handler,
	)
	RegisterHandler(pattern string, handler http.Handler)
	NewGroup(
		pattern string,
		middlewares ...func(next http.Handler) http.Handler,
	) *Router
	RegisterGroup(router *Router)
	Pattern() string
	RelativePath() string
	FullPath() string
	Method() string
}

RouterWrapper is the interface for the routes

Jump to

Keyboard shortcuts

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