controllers

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 3, 2022 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BootStrap

func BootStrap()

BootStrap creates the actual controllers from the controllers registry. This function must be called before starting the http server.

Types

type Controller

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

A Controller is a server function that is called through an http route.

type Group

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

A Group is used to group routes with common prefix, in order to apply it specific middlewares.

var Registry *Group

Registry is the central collection of all the application controllers

func (*Group) AddController

func (g *Group) AddController(method, relativePath string, fnct server.HandlerFunc)

AddController creates a controller for the given method and path and sets fnct as the base handler function for this controller. It panics if such a controller already exists.

func (*Group) AddGroup

func (g *Group) AddGroup(relativePath string) *Group

AddGroup adds a sub-group to this group with the given relativePath and returns the newly created group. It panics if the group already exists.

func (*Group) AddMiddleWare

func (g *Group) AddMiddleWare(fnct server.HandlerFunc)

AddMiddleWare adds the given fnct as a new middleware for this group fnct will be executed before any other middleware of this group.

Call the Next() method of fnct's context to call the next middleware. If Next is not called explicitly, the next middleware is called automatically at the end of fnct.

func (*Group) AddStatic

func (g *Group) AddStatic(relativePath, fsPath string)

AddStatic creates a new route at relativePath that will serve the static files found at fsPath on the file system.

func (*Group) ExtendController

func (g *Group) ExtendController(method, relativePath string, fnct server.HandlerFunc)

ExtendController extends the controller for the given method and path with the given fnct handler function.

The handler fnct should call its context Super() method to call the original controller implementation. Note that if Super() is not called explicitly, the original implementation is automatically called at the end of the handler fnct. If this is not the wanted behaviour, use OverrideController instead.

ExtendController panics if such a controller does not exist

func (*Group) GetGroup

func (g *Group) GetGroup(relativePath string) (*Group, bool)

GetGroup returns the sub group of this group for the given relativePath the returned boolean is 'false' if the sub group does not exists for this group

func (*Group) HasController

func (g *Group) HasController(method, relativePath string) bool

HasController returns true if the given method and path already has a controller function

func (*Group) MustGetGroup

func (g *Group) MustGetGroup(relativePath string) *Group

MustGetGroup returns the sub group of this group for the given relativePath It panics if this group does not exist

func (*Group) OverrideController

func (g *Group) OverrideController(method, relativePath string, fnct server.HandlerFunc)

OverrideController overrides the controller for the given method and path with the given fnct handler function.

Call to the handler fnct context Super() method has no effect, since all previous implementations are discarded. If this is not the wanted behaviour, use ExtendController instead.

OverrideController panics if such a controller does not exist

type Route

type Route struct {
	Path   string
	Method string
}

A Route is the combination of a URI (Path) and an HTTP Method

Jump to

Keyboard shortcuts

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