route

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindJSON

func BindJSON(payload interface{}, v interface{}) (err error)

BindJSON data to a request handler

func BindString

func BindString(payload string, s *string) (err error)

BindString data to a request handler

Types

type BaseRequest

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

BaseRequest embeddable

func (*BaseRequest) Context

func (r *BaseRequest) Context() (ctx RequestContext)

Context get the context of the request

func (*BaseRequest) Initialize

func (r *BaseRequest) Initialize(ctx RequestContext, tx *storage.Transaction)

Initialize the request

func (*BaseRequest) Token

func (r *BaseRequest) Token() (token *string)

Token used for the request

func (*BaseRequest) Tx

func (r *BaseRequest) Tx() (tx *storage.Transaction)

Tx get the transaction for the request

type BaseRequestContext

type BaseRequestContext struct {
	service.Container
	Language *language.Tag
	// contains filtered or unexported fields
}

BaseRequestContext of a connection

func NewRequestContext

func NewRequestContext(c service.Container, language *language.Tag, token string) (r *BaseRequestContext)

NewRequestContext creates a new context instance

func (*BaseRequestContext) Token

func (b *BaseRequestContext) Token() (token *string)

Token used in the context

type Binder

type Binder interface {
	Bind(interface{}, Request) (err error)
}

Binder binds data to a request handler

type Executer

type Executer interface {
	Execute() (data interface{}, err error)
}

Executer for a request handler Returns data that is used as response (can also be nil)

type Group

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

Group of routes

func NewGroup

func NewGroup(middleware ...Middleware) (g *Group)

NewGroup constructor

func (*Group) ADD

func (g *Group) ADD(path string, generator HandlerGenerator) (err error)

ADD handler

func (*Group) AddGroup

func (g *Group) AddGroup(path string, middleware ...Middleware) (newGroup *Group, err error)

AddGroup create a group below the current group

func (*Group) BasePath

func (g *Group) BasePath() (path string)

BasePath of this route group

func (*Group) DELETE

func (g *Group) DELETE(path string, generator HandlerGenerator) (err error)

DELETE handler

func (*Group) GET

func (g *Group) GET(path string, generator HandlerGenerator) (err error)

GET handler

func (*Group) GetGroups

func (g *Group) GetGroups() (groups []*Group)

GetGroups returns a slice of groups that exist below this group

func (*Group) GetMiddleware

func (g *Group) GetMiddleware() (middleware []Middleware)

GetMiddleware returns the middleware handler of the group

func (*Group) GetRoutes

func (g *Group) GetRoutes() (routes map[Type]map[string]HandlerGenerator)

GetRoutes returns the handler map grouped by type and path

func (*Group) Handle

func (g *Group) Handle(t Type, path string, generator HandlerGenerator) (err error)

Handle a request (you can also use the aliases GET, UPDATE, ADD, DELETE)

func (*Group) HasGroup

func (g *Group) HasGroup(path string) (exists bool)

HasGroup checks if a group exists for this group

func (*Group) HasRoute

func (g *Group) HasRoute(t Type, path string) (exists bool)

HasRoute checks if a route exists for this group

func (*Group) Path

func (g *Group) Path() (path string)

Path of this route group

func (*Group) UPDATE

func (g *Group) UPDATE(path string, generator HandlerGenerator) (err error)

UPDATE handler

type Grouper

type Grouper interface {
	AddGroup(path string, middleware ...Middleware) (newGroup *Group, err error)
	HasRoute(t Type, path string) (exists bool)
	HasGroup(path string) (exists bool)
	GET(path string, generator HandlerGenerator) (err error)
	UPDATE(path string, generator HandlerGenerator) (err error)
	ADD(path string, generator HandlerGenerator) (err error)
	DELETE(path string, generator HandlerGenerator) (err error)
	Handle(t Type, path string, generator HandlerGenerator) (err error)
	BasePath() (path string)
	Path() (path string)
	GetMiddleware() (middleware []Middleware)
	GetGroups() (groups []*Group)
	GetRoutes() (routes map[Type]map[string]HandlerGenerator)
}

Grouper group interface

type Handler

type Handler interface {
	Binder
	Executer
}

Handler for a websocket request

type HandlerGenerator

type HandlerGenerator func() Handler

HandlerGenerator instantiates a handler

type Middleware

type Middleware interface {
	Execute(ctx RequestContext) (cancel bool, err error)
}

Middleware for route groups

type Request

type Request interface {
	Initialize(ctx RequestContext, tx *storage.Transaction)
	Context() (ctx RequestContext)
	Tx() (tx *storage.Transaction)
	Token() (token *string)
}

Request to the websocket

type RequestContext

type RequestContext interface {
	service.Container
	Token() (token *string)
}

RequestContext context functions for a request

type Type

type Type uint8

Type type of a request

const (
	// GET :
	GET Type = 1
	// UPDATE :
	UPDATE Type = 2
	// ADD :
	ADD Type = 3
	// DELETE :
	DELETE Type = 4
)

Jump to

Keyboard shortcuts

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