activator

package
v8.3.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2017 License: BSD-3-Clause Imports: 5 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`.
	ErrMissingControllerInstance = errors.New("controller should have a field of Controller type")
	// ErrInvalidControllerType fired when the "Controller" field is not
	// the correct type.
	ErrInvalidControllerType = errors.New("controller instance is not a valid implementation")
)
View Source
var ErrControlSkip = errors.New("skip control")

ErrControlSkip never shows up, used to determinate if a control's Load return error is critical or not, `ErrControlSkip` means that activation can continue and skip this control.

View Source
var ErrMissingHTTPMethodFunc = errors.New(`controller can not be activated,
 missing a compatible HTTP method function, i.e Get()`)

ErrMissingHTTPMethodFunc fired when the controller doesn't handle any valid HTTP method.

Functions

func Register

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

Register receives a "controller", a pointer of an instance which embeds the `Controller`, the value of "baseControllerFieldName" should be `Controller` if embedded and "controls" that can intercept on controller activation and on the controller's handler, at serve-time.

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 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 MethodFunc

type MethodFunc struct {
	Index      int
	HTTPMethod string
}

MethodFunc is part of the `TController`, it contains the index for a specific http method, taken from user's controller struct.

type RegisterFunc

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

RegisterFunc used by the caller to register the result routes.

type TControl

type TControl interface {
	// Load should returns nil  if its `Handle`
	// should be called on serve time.
	//
	// if error is filled then controller info
	// is not created and that error is returned to the
	// high-level caller, but the `ErrControlSkip` can be used
	// to skip the control without breaking the rest of the registration.
	Load(t *TController) error
	// Handle executes the control.
	// It accepts the context, the new controller instance
	// and the specific methodFunc based on the request.
	Handle(ctx context.Context, controller reflect.Value, methodFunc func())
}

TControl is an optional feature that an app can benefit by using its own custom controls to control the flow inside a controller, they are being registered per controller.

Naming: I could find better name such as 'Control', but I can imagine the user's confusion about `Controller` and `Control` types, they are different but they may use that as embedded, so it can not start with the world "C..". The best name that shows the relation between this and the controller type info struct(TController) is the "TControl", `TController` is prepended with "T" for the same reasons, it's different than `Controller`, the TController is the "description" of the user's `Controller` embedded field.

func CallableControl

func CallableControl(funcName ...string) TControl

CallableControl is a generic-propose `TControl` which finds one function in the user's controller's struct based on the possible "funcName(s)" and executes that inside the handler, at serve-time, by passing the current request's `iris/context/#Context`.

func MethodControl

func MethodControl() TControl

MethodControl loads and serve the main functionality of the controllers, which is to run a function based on the http method (pre-computed).

func ModelControl

func ModelControl() TControl

ModelControl returns a TControl which is responsible to load and handle the `Model(s)` inside a controller struct via the `iris:"model"` tag field.

func PersistenceDataControl

func PersistenceDataControl() TControl

PersistenceDataControl loads and re-stores the persistence data by scanning the original `TController.Value` instance of the user's controller.

type TController

type TController struct {
	// 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

	// the actual method functions
	// i.e for "GET" it's the `Get()`
	//
	// Here we have a strange relation by-design.
	// It contains the methods
	// but we have different handlers
	// for each of these methods,
	// while in the same time all of these
	// are depend from this TypeInfo struct.
	// So we have TypeInfo -> Methods -> Each(TypeInfo, Method.Index)
	// -> Handler for X HTTPMethod, see `Register`.
	Methods []MethodFunc
	// 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{},
	controls []TControl) (TController, error)

ActivateController returns a new controller type info description. A TController is not useful for the end-developer but it can be used for debugging.

Jump to

Keyboard shortcuts

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