router

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

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

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 = "@"

Functions

func NetHttpHandlerFromHttp

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

Types

type GroupHandler

type GroupHandler func(r *Wrapper)

type Handler

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

type RequestResolver

type RequestResolver interface {
	ResolveRequest(r contracts.RequestContract, runtime *kernel.Application)
}

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(app *kernel.Application) *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) CRUD

func (w *Wrapper) CRUD(path string, handler CRUDHandler, middleware ...string)

CRUD register simple crud routes

func (*Wrapper) Delete

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

func (*Wrapper) Get

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

func (*Wrapper) Group

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

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 added in v0.0.2

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

func (Wrapper) MatchString added in v0.0.2

func (r Wrapper) MatchString(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,RequestContract,[]byte or JsonAble

func (*Wrapper) ResolveRequest

func (w *Wrapper) ResolveRequest(rs RequestResolver)

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