router

package module
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2024 License: BSD-3-Clause Imports: 6 Imported by: 2

README

router

Variables

var Methods = []string{"GET", "POST", "OPTIONS", "PUT", "PATCH", "DELETE", "WS"}

Functions

func IsMethod

func IsMethod(method string) int

func NewRouteTable

func NewRouteTable[T any]() *routeTree[T]

Types

type Router

type Router[T any] struct { ... }

func NewRouter

func NewRouter[T any]() *Router[T]

func (*Router[T]) Add

func (r *Router[T]) Add(verb, path string, thing *T)

func (*Router[T]) All

func (r *Router[T]) All() []*T

func (*Router[T]) Find

func (r *Router[T]) Find(verb, path string) *T


Readme created from Go doc with goreadme

Documentation

Overview

Package router implements an http router

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Matcher

type Matcher[T any] interface {
	Add(r *RouteDefinition, t *T)
	Find(*http.Request) *T
	All() []Route[T]
}

func NewPathMatcher

func NewPathMatcher[T any]() Matcher[T]

type PathMatcher

type PathMatcher[T any] struct {
	// contains filtered or unexported fields
}

PathMatcher holds information for routing urls with wildcard

func (*PathMatcher[T]) Add

func (rt *PathMatcher[T]) Add(req *RouteDefinition, t *T)

Add a new route to the table

func (*PathMatcher[T]) All

func (rt *PathMatcher[T]) All() []Route[T]

func (*PathMatcher[T]) Find

func (n *PathMatcher[T]) Find(req *http.Request) *T

func (*PathMatcher[T]) Routes

func (rt *PathMatcher[T]) Routes() []routeInfo[T]

type Route

type Route[T any] struct {
	Req *http.Request
	T   *T
}

func (Route[T]) String

func (r Route[T]) String() string

type RouteDefinition

type RouteDefinition struct {
	Method string
	Port   string
	Domain string
	Scheme string
	Path   string
}

func NewRouteDefinition

func NewRouteDefinition(def string) *RouteDefinition

type Router

type Router[T any] methodMatcher[T]

func NewRouter

func NewRouter[T any]() *Router[T]

func (Router[T]) Add

func (r Router[T]) Add(req *RouteDefinition, t *T)

func (Router[T]) AddByPath

func (r Router[T]) AddByPath(path string, t *T)

func (Router[T]) All

func (r Router[T]) All() []Route[T]

func (Router[T]) Find

func (r Router[T]) Find(req *http.Request) *T

Jump to

Keyboard shortcuts

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