router

package
v1.2.7 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2024 License: BSD-3-Clause Imports: 22 Imported by: 4

Documentation

Index

Constants

View Source
const (
	GET     = 1
	HEAD    = 1 << 1
	POST    = 1 << 2
	PUT     = 1 << 3
	PATCH   = 1 << 4
	DELETE  = 1 << 5
	OPTIONS = 1 << 6
	ANY     = GET | HEAD | POST | PUT | PATCH | DELETE | OPTIONS
)

Variables

View Source
var DefaultResultHandler = func(val []reflect.Value, err error) contracts.ResponseContract {
	if err != nil {
		return content.ErrResponseFromError(err, 500, nil)
	}

	if len(val) < 1 {
		return content.TextResponse("", 200)
	}

	if len(val) > 1 {
		e := val[1].Interface()
		er, isErr := e.(error)
		if isErr && e != nil {
			return content.ErrResponseFromError(er, 500, nil)
		}
	}

	data := val[0].Interface()

	return convertResponse(data)
}
View Source
var MethodSplitter = "@"
View Source
var NotFoundHandler = func(r contracts.RequestContract) contracts.ResponseContract {
	return content.ErrResponseFromError(errors.NotFound("Not Found"), 404, nil)
}
View Source
var ResponseFallbacker = func(data interface{}) contracts.ResponseContract {
	return content.JsonResponse(data, 200, nil)
}

Functions

func AppendSlash

func AppendSlash(path string) string

func JoinPaths

func JoinPaths(paths ...string) string

func NetHttpHandlerFromHttp

func NetHttpHandlerFromHttp(request *content.NetHttpRequest, h http.Handler) contracts.ResponseContract

Types

type ContainerRegister

type ContainerRegister func(request contracts.RequestContract) container.Interface

type GroupHandler

type GroupHandler func(r *Wrapper)

type Handler

type Handler interface {
	HandleRoute(r contracts.RequestContract) contracts.ResponseContract
}

type ParamRoute added in v1.0.0

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

func (*ParamRoute) Handler added in v1.0.0

func (p *ParamRoute) Handler() RouteHandler

Handler route handler

func (*ParamRoute) IsValid added in v1.0.0

func (p *ParamRoute) IsValid() bool

func (*ParamRoute) Middleware added in v1.0.0

func (p *ParamRoute) Middleware() []string

func (*ParamRoute) Name added in v1.0.0

func (p *ParamRoute) Name() string

Name of route

func (*ParamRoute) Partials added in v1.0.0

func (p *ParamRoute) Partials() []partial

Partials partials of route path

func (*ParamRoute) Path added in v1.0.0

func (p *ParamRoute) Path() string

Path path

func (*ParamRoute) PipeFuncs added in v1.0.0

func (p *ParamRoute) PipeFuncs() []pipeline.PipeFunc

PipeFuncs return pipeline middleware

func (*ParamRoute) SetMiddleware added in v1.0.0

func (p *ParamRoute) SetMiddleware(middleware []string) *ParamRoute

type ParamSlice

type ParamSlice [][]byte

type Params

type Params map[string][]byte

type ResultHandler

type ResultHandler func(val []reflect.Value, err error) contracts.ResponseContract

ResultHandler handle return result

type RouteHandler

RouteHandler normal route handler

func NewRouteHandlerFromHttp

func NewRouteHandlerFromHttp(h http.Handler) RouteHandler

type Wrapper

type Wrapper struct {
	ResultHandler ResultHandler
	// contains filtered or unexported fields
}

func NewWrapper

func NewWrapper(ps ...string) *Wrapper

func (*Wrapper) BindController

func (w *Wrapper) BindController(name string, controller interface{})

BindController bind single controller

func (*Wrapper) BindControllers

func (w *Wrapper) BindControllers(controllers map[string]interface{})

BindControllers bind controllers

func (*Wrapper) Delete

func (w *Wrapper) Delete(path string, handler interface{}) *routesHolder

func (*Wrapper) FastHttpFileServer

func (w *Wrapper) FastHttpFileServer(path, root string, stripSlashes int) *routesHolder

func (*Wrapper) Get

func (w *Wrapper) Get(path string, handler interface{}) *routesHolder

func (*Wrapper) Group

func (w *Wrapper) Group(g GroupHandler, prefix ...string) *routesHolder

func (Wrapper) HandleDelete

func (r Wrapper) HandleDelete(path string, handler RouteHandler) *routesHolder

func (Wrapper) HandleGet

func (r Wrapper) HandleGet(path string, handler RouteHandler) *routesHolder

HandleGet get method with route handler

func (Wrapper) HandlePatch

func (r Wrapper) HandlePatch(path string, handler RouteHandler) *routesHolder

func (Wrapper) HandlePost

func (r Wrapper) HandlePost(path string, handler RouteHandler) *routesHolder

func (Wrapper) HandlePut

func (r Wrapper) HandlePut(path string, handler RouteHandler) *routesHolder

func (Wrapper) Match

func (r Wrapper) Match(request contracts.RequestContract) *ParamRoute

func (Wrapper) MatchBytes

func (r Wrapper) MatchBytes(request contracts.RequestContract) *ParamRoute

Depracated MatchBytes, using MatchTree

func (Wrapper) MatchString

func (r Wrapper) MatchString(request contracts.RequestContract) *ParamRoute

Depracated MatchString, using MatchTree

func (Wrapper) MatchTree

func (r Wrapper) MatchTree(request contracts.RequestContract) *ParamRoute

func (*Wrapper) Patch

func (w *Wrapper) Patch(path string, handler interface{}) *routesHolder

func (*Wrapper) Post

func (w *Wrapper) Post(path string, handler interface{}) *routesHolder

func (*Wrapper) Put

func (w *Wrapper) Put(path string, handler interface{}) *routesHolder

func (Wrapper) Register

func (r Wrapper) Register(method int, path string, handler RouteHandler) *routesHolder

Register register route

func (*Wrapper) RegisterAction

func (w *Wrapper) RegisterAction(method int, path string, handler interface{}) *routesHolder

RegisterAction register route with giving handler

'handler' can be string(eg: "home@Index",), RouteHandler
or any func returns string,ResponseContract,[]byte or struct (auto convert to json response)

func (Wrapper) Routes

func (r Wrapper) Routes() map[string][]*ParamRoute

Jump to

Keyboard shortcuts

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