activator

package
v8.5.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2017 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingControllerInstance is a static error which fired from `Controller` when
	// the passed "c" instnace is not a valid type of `Controller` or `C`.
	ErrMissingControllerInstance = errors.New("controller should have a field of mvc.Controller or mvc.C type")
	// ErrInvalidControllerType fired when the "Controller" field is not
	// the correct type.
	ErrInvalidControllerType = errors.New("controller instance is not a valid implementation")
)

Functions

func CallOnActivate

func CallOnActivate(controller interface{},
	bindValues *[]interface{}, registerFunc RegisterFunc)

CallOnActivate simply calls the "controller"'s `OnActivate(*ActivatePayload)` function, if any.

Look `activator.go#Register` and `ActivateListener` for more.

func Register

func Register(controller BaseController, bindValues []interface{},
	registerFunc RegisterFunc) error

Register receives a "controller", a pointer of an instance which embeds the `Controller`, the value of "baseControllerFieldName" should be `Controller`.

func RegisterMethodHandlers

func RegisterMethodHandlers(t TController, registerFunc RegisterFunc)

RegisterMethodHandlers receives a `TController`, description of the user's controller, and calls the "registerFunc" for each of its method handlers.

Not useful for the end-developer, but may needed for debugging at the future.

Types

type ActivateListener

type ActivateListener interface {
	// OnActivate accepts a pointer to the `ActivatePayload`.
	//
	// The `Controller` can make use of the `OnActivate` function
	// to register custom routes
	// or modify the provided values that will be binded to the
	// controller later on.
	//
	// Look `ActivatePayload` for more.
	OnActivate(*ActivatePayload)
}

ActivateListener is an interface which should be declared on a Controller which needs to register or change the bind values that the caller-"user" has been passed to; via the `app.Controller`. If that interface is completed by a controller then the `OnActivate` function will be called ONCE, NOT in every request but ONCE at the application's lifecycle.

type ActivatePayload

type ActivatePayload struct {
	BindValues *[]interface{}
	Handle     RegisterFunc
}

ActivatePayload contains the necessary information and the ability to alt a controller's registration options, i.e the binder.

With `ActivatePayload` the `Controller` can register custom routes or modify the provided values that will be binded to the controller later on.

func (*ActivatePayload) EnsureBindValue

func (i *ActivatePayload) EnsureBindValue(bindValue interface{}) bool

EnsureBindValue will make sure that this "bindValue" will be registered to the controller's binder if its type is not already passed by the caller..

For example, on `SessionController` it looks if *sessions.Sessions has been binded from the caller and if not then the "bindValue" will be binded and used as a default sessions manager instead.

At general, if the caller has already provided a value with the same Type then the "bindValue" will be ignored and not be added to the controller's bind values.

Returns true if the caller has NOT already provided a value with the same Type and "bindValue" is NOT ignored therefore is appended to the controller's bind values.

type BaseController

type BaseController interface {
	SetName(name string)
	BeginRequest(ctx context.Context)
	EndRequest(ctx context.Context)
}

BaseController is the controller interface, which the main request `Controller` will implement automatically. End-User doesn't need to have any knowledge of this if she/he doesn't want to implement a new Controller type.

type RegisterFunc

type RegisterFunc func(relPath string, httpMethod string, handler ...context.Handler)

RegisterFunc used by the caller to register the result routes.

type TController

type TController struct {
	// The name of the front controller struct.
	Name string
	// FullName it's the last package path segment + "." + the Name.
	// i.e: if login-example/user/controller.go, the FullName is "user.Controller".
	FullName string
	// the type of the user/dev's "c" controller (interface{}).
	Type reflect.Type
	// it's the first passed value of the controller instance,
	// we need this to collect and save the persistence fields' values.
	Value reflect.Value
	// contains filtered or unexported fields
}

TController is the type of the controller, it contains all the necessary information to load and serve the controller to the outside world, think it as a "supervisor" of your Controller which cares about you.

func ActivateController

func ActivateController(base BaseController, bindValues []interface{}) (TController, error)

ActivateController returns a new controller type info description.

func (TController) HandlerOf

func (t TController) HandlerOf(methodFunc methodfunc.MethodFunc) context.Handler

HandlerOf builds the handler for a type based on the specific method func.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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