router

package
v0.0.0-...-7690095 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2017 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RouteHard
	RouteRegex
	RouteTyped
	RouteSoft
)
View Source
const (
	MatchtypeInt = iota
	MatchtypeInt64
	MatchtypeFloat
	MatchtypeFloat64
)

Variables

View Source
var ErrInvalidHandler = errors.New("invalid handler")

Functions

func HandleHeaders

func HandleHeaders(ctxt *web.Context, ep EndPoint, h http.Handler) (served bool)

func ServeOptions

func ServeOptions(methods []string, w http.ResponseWriter, r *http.Request, origin map[string]string)

func SetHeaderOrigin

func SetHeaderOrigin(w http.ResponseWriter, r *http.Request, origin map[string]string)

Types

type ContextHTTPHandler

type ContextHTTPHandler struct {
	web.ContextHandler
}

func (ContextHTTPHandler) ServeHTTP

func (ch ContextHTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ContextHTTPHandlerFunc

type ContextHTTPHandlerFunc func(*web.Context)

func (ContextHTTPHandlerFunc) ServeContextHTTP

func (f ContextHTTPHandlerFunc) ServeContextHTTP(ctxt *web.Context)

func (ContextHTTPHandlerFunc) ServeHTTP

type EndPoint

type EndPoint interface {
	Handlers() map[string]http.Handler
	GetHandler() http.Handler
	PostHandler() http.Handler
	PutHandler() http.Handler
	PatchHandler() http.Handler
	DeleteHandler() http.Handler
	HeadHandler() http.Handler
	SetHandler(interface{}, ...string) error
	Methods() []string
	GetRequestedEndPoint(*http.Request, []string, []string) *RequestedEndPoint
	PrependVarName(...string)
	AppendVarName(...string)
}

type EndPointOrigin

type EndPointOrigin interface {
	Origin() map[string]string
}

type Host

type Host interface {
	SetHost(host string, canon string)
	Host() string
	FullHost() string
	HostCanon() string
	FullHostCanon() string
}

type OptionsHandler

type OptionsHandler interface {
	ServeOptions(http.ResponseWriter, *http.Request, map[string]string)
}

type PathPrefix

type PathPrefix interface {
	SetPathPrefix(path string, canon string)
	PathPrefix() string
	FullPathPrefix() string // the full path prefix including its parent's & ancestors'
	PathPrefixCanon() string
	FullPathPrefixCanon() string
}

type RequestedEndPoint

type RequestedEndPoint struct {
	Ext      string
	UPath    web.UPath
	PData    web.PData
	Method   string
	Handler  http.Handler
	EndPoint EndPoint
}

type Route

type Route interface {
	HasRoute(string) bool
	FindRequestedEndPoint(p string, r *http.Request) *RequestedEndPoint
	FindEndPoint(p []string, data []string) (EndPoint, []string, []string)
	HardEndPoint() EndPoint
	SoftEndPoint() EndPoint
	Switch(string) Switch
	BuildRoute(string) ([][]string, []Route)
	Handle(string, interface{}, ...string) EndPoint
}

type RouteMatcher

type RouteMatcher interface {
	Match(r *http.Request, value map[string]interface{}) (bool, map[string]interface{})
}

type RouteMatcherFunc

type RouteMatcherFunc func(r *http.Request, value map[string]interface{}) (bool, map[string]interface{})

func (RouteMatcherFunc) Match

func (f RouteMatcherFunc) Match(r *http.Request, value map[string]interface{}) (bool, map[string]interface{})

type Router

type Router interface {
	CanRouteRequest(*http.Request, map[string]interface{}) (bool, map[string]interface{})
	SetMatcher(name string, rm RouteMatcher)
	DeleteMatcher(name string)
	Matcher(name string) RouteMatcher
	SubRouter(string) Router
	AddRouter(string, Router) bool
	DelRouter(Router)
	DelRouterByName(string)
	SetParent(Router) bool
	ResetParent()
	Parent() Router
	HasParent() bool
	FindRequestedEndPoint(value map[string]interface{}, r *http.Request) (Router, *RequestedEndPoint)
	ServeHTTP(http.ResponseWriter, *http.Request)
	ServeRequestedEndPoint(http.ResponseWriter, *http.Request, *RequestedEndPoint)
	Handle(string, interface{}, ...string) EndPoint
}

type SunnyEndPoint

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

func (*SunnyEndPoint) AppendVarName

func (se *SunnyEndPoint) AppendVarName(name ...string)

func (*SunnyEndPoint) DeleteHandler

func (se *SunnyEndPoint) DeleteHandler() http.Handler

func (*SunnyEndPoint) GetHandler

func (se *SunnyEndPoint) GetHandler() http.Handler

func (*SunnyEndPoint) GetRequestedEndPoint

func (se *SunnyEndPoint) GetRequestedEndPoint(r *http.Request, upath []string, data []string) *RequestedEndPoint

func (*SunnyEndPoint) Handler

func (se *SunnyEndPoint) Handler(method string) http.Handler

func (*SunnyEndPoint) Handlers

func (se *SunnyEndPoint) Handlers() map[string]http.Handler

func (*SunnyEndPoint) HeadHandler

func (se *SunnyEndPoint) HeadHandler() (head http.Handler)

func (*SunnyEndPoint) Methods

func (se *SunnyEndPoint) Methods() (methods []string)

func (*SunnyEndPoint) PatchHandler

func (se *SunnyEndPoint) PatchHandler() http.Handler

func (*SunnyEndPoint) PostHandler

func (se *SunnyEndPoint) PostHandler() http.Handler

func (*SunnyEndPoint) PrependVarName

func (se *SunnyEndPoint) PrependVarName(names ...string)

func (*SunnyEndPoint) PutHandler

func (se *SunnyEndPoint) PutHandler() http.Handler

func (*SunnyEndPoint) SetHandler

func (se *SunnyEndPoint) SetHandler(handler interface{}, method ...string) error

type SunnyRoute

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

func NewSunnyRoute

func NewSunnyRoute() *SunnyRoute

func (*SunnyRoute) BuildRoute

func (sr *SunnyRoute) BuildRoute(p string) (varnames [][]string, rts []Route)

func (*SunnyRoute) FindEndPoint

func (sr *SunnyRoute) FindEndPoint(p []string, data []string) (EndPoint, []string, []string)

func (*SunnyRoute) FindRequestedEndPoint

func (sr *SunnyRoute) FindRequestedEndPoint(p string, r *http.Request) *RequestedEndPoint

func (*SunnyRoute) Handle

func (sr *SunnyRoute) Handle(p string, h interface{}, method ...string) (ep EndPoint)

func (*SunnyRoute) HardEndPoint

func (sr *SunnyRoute) HardEndPoint() EndPoint

func (*SunnyRoute) HasRoute

func (sr *SunnyRoute) HasRoute(p string) bool

func (*SunnyRoute) SoftEndPoint

func (sr *SunnyRoute) SoftEndPoint() EndPoint

func (*SunnyRoute) SplitPath

func (sr *SunnyRoute) SplitPath(p string) (pathsplit []string)

func (*SunnyRoute) Switch

func (sr *SunnyRoute) Switch(p string) Switch

type SunnyRouter

type SunnyRouter struct {
	Route
	// contains filtered or unexported fields
}

func NewSunnyRouter

func NewSunnyRouter() *SunnyRouter

func (*SunnyRouter) AddRouter

func (sr *SunnyRouter) AddRouter(name string, rt Router) (ok bool)

func (*SunnyRouter) CanRouteRequest

func (sr *SunnyRouter) CanRouteRequest(r *http.Request, value map[string]interface{}) (bool, map[string]interface{})

func (*SunnyRouter) DelRouter

func (sr *SunnyRouter) DelRouter(rt Router)

func (*SunnyRouter) DelRouterByName

func (sr *SunnyRouter) DelRouterByName(name string)

func (*SunnyRouter) DeleteMatcher

func (sr *SunnyRouter) DeleteMatcher(name string)

func (*SunnyRouter) FindRequestedEndPoint

func (sr *SunnyRouter) FindRequestedEndPoint(value map[string]interface{}, r *http.Request) (Router, *RequestedEndPoint)

func (*SunnyRouter) FullHost

func (sr *SunnyRouter) FullHost() string

func (*SunnyRouter) FullHostCanon

func (sr *SunnyRouter) FullHostCanon() string

func (*SunnyRouter) FullPathPrefix

func (sr *SunnyRouter) FullPathPrefix() string

func (*SunnyRouter) FullPathPrefixCanon

func (sr *SunnyRouter) FullPathPrefixCanon() string

func (*SunnyRouter) HasParent

func (sr *SunnyRouter) HasParent() bool

func (*SunnyRouter) Host

func (sr *SunnyRouter) Host() string

func (*SunnyRouter) HostCanon

func (sr *SunnyRouter) HostCanon() string

func (*SunnyRouter) MatchHost

func (sr *SunnyRouter) MatchHost(r *http.Request, value map[string]interface{}) (bool, map[string]interface{})

func (*SunnyRouter) MatchPathPrefix

func (sr *SunnyRouter) MatchPathPrefix(r *http.Request, value map[string]interface{}) (bool, map[string]interface{})

func (*SunnyRouter) Matcher

func (sr *SunnyRouter) Matcher(name string) RouteMatcher

func (*SunnyRouter) Parent

func (sr *SunnyRouter) Parent() Router

func (*SunnyRouter) PathPrefix

func (sr *SunnyRouter) PathPrefix() string

func (*SunnyRouter) PathPrefixCanon

func (sr *SunnyRouter) PathPrefixCanon() string

func (*SunnyRouter) ResetParent

func (sr *SunnyRouter) ResetParent()

func (*SunnyRouter) Router

func (sr *SunnyRouter) Router(name string) Router

func (*SunnyRouter) Routers

func (sr *SunnyRouter) Routers() map[string]Router

func (*SunnyRouter) ServeHTTP

func (sr *SunnyRouter) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*SunnyRouter) ServeRequestedEndPoint

func (sr *SunnyRouter) ServeRequestedEndPoint(w http.ResponseWriter, r *http.Request, rep *RequestedEndPoint)

func (*SunnyRouter) SetHost

func (sr *SunnyRouter) SetHost(host string, canon string)

func (*SunnyRouter) SetMatcher

func (sr *SunnyRouter) SetMatcher(name string, rm RouteMatcher)

func (*SunnyRouter) SetParent

func (sr *SunnyRouter) SetParent(rt Router) bool

func (*SunnyRouter) SetPathPrefix

func (sr *SunnyRouter) SetPathPrefix(path string, canon string)

func (*SunnyRouter) SubRouter

func (sr *SunnyRouter) SubRouter(name string) (rt Router)

type SunnySwitch

type SunnySwitch struct {
	Route
	// contains filtered or unexported fields
}

func (*SunnySwitch) Handle

func (ss *SunnySwitch) Handle(p string, h http.Handler) (ep EndPoint)

func (*SunnySwitch) PrependVarName

func (ss *SunnySwitch) PrependVarName(names ...string)

func (*SunnySwitch) Switch

func (ss *SunnySwitch) Switch(p string) (s Switch)

type Switch

type Switch interface {
	HasRoute(string) bool
	Handle(string, http.Handler) EndPoint
	BuildRoute(string) ([][]string, []Route)
	Switch(string) Switch
	PrependVarName(...string)
}

Jump to

Keyboard shortcuts

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