Documentation ¶
Index ¶
- Constants
- func IsCanonicalAction(actionName string) bool
- type AbstractController
- type AbstractModel
- type Action
- type ActionController
- type ActionFunc
- type C
- func (c *C) Action(name string, a ActionFunc)
- func (c *C) AfterAction(cb Callback, only ...string)
- func (c *C) AppendAfterAction(cb Callback, only ...string)
- func (c *C) AppendAroundAction(cb CallbackAround, only ...string)
- func (c *C) AppendBeforeAction(cb Callback, only ...string)
- func (c *C) AroundAction(cb CallbackAround, only ...string)
- func (c *C) BeforeAction(cb Callback, only ...string)
- func (c *C) Create(a ActionFunc)
- func (c *C) Destroy(a ActionFunc)
- func (c *C) Index(a ActionFunc)
- func (c *C) Permit(params []activerecord.Attribute, names ...string)
- func (c *C) Show(a ActionFunc)
- func (c *C) Update(a ActionFunc)
- type Callback
- type CallbackAround
- type Constraints
- type Context
- type ErrActionNotFound
- type Mapper
- type Matcher
- type NamedAction
- type Parameters
- type QueryAttribute
- type Request
- type Response
- type Result
- type StrongParameters
Constants ¶
const ( ActionCreate = "create" ActionUpdate = "update" ActionShow = "show" ActionIndex = "index" ActionDestroy = "destroy" )
Variables ¶
This section is empty.
Functions ¶
func IsCanonicalAction ¶
Types ¶
type AbstractController ¶
type AbstractController interface {
ActionMethods() []Action
}
type AbstractModel ¶
type AbstractModel interface { Name() string PrimaryKey() string AttributeNames() []string AttributeForInspect(attrName string) activerecord.Attribute AttributesForInspect(attrNames ...string) []activerecord.Attribute ReflectOnAllAssociations() []*activerecord.AssociationReflection }
type Action ¶
type Action interface { ActionName() string ActionConstraints() Constraints Process(ctx *Context) Result }
type ActionController ¶
type ActionController struct {
// contains filtered or unexported fields
}
func Initialize ¶
func Initialize(init func(*C)) (*ActionController, error)
func New ¶
func New(init func(*C)) *ActionController
func (*ActionController) Action ¶
func (c *ActionController) Action(actionName string) Action
func (*ActionController) ActionMethods ¶
func (c *ActionController) ActionMethods() []Action
func (*ActionController) HasAction ¶
func (c *ActionController) HasAction(actionName string) bool
type ActionFunc ¶
func (ActionFunc) Process ¶
func (fn ActionFunc) Process(ctx *Context) Result
type C ¶
type C struct {
// contains filtered or unexported fields
}
func (*C) Action ¶
func (c *C) Action(name string, a ActionFunc)
func (*C) AfterAction ¶
func (*C) AppendAfterAction ¶
func (*C) AppendAroundAction ¶
func (c *C) AppendAroundAction(cb CallbackAround, only ...string)
AppendAroundAction appends a callback around action. See CallbackAround for parameter details.
Use the around callback to wrap the action with extra logic, e.g. execute all operations within an action in a database transaction.
func WrapInTransaction( ctx *actioncontroller.Context, action actioncontroller.Action ) (result actioncontroller.Result) { err := activerecord.Transaction(ctx, func() error { result = action.Process(ctx) return result.Err() }) if err != nil { return actionview.ContentResult(nil, err) } return nil } ProductsController := actioncontroller.New(func(c *actioncontroller.C) { c.AppendAroundAction(WrapInTransaction) })
func (*C) AppendBeforeAction ¶
AppendBeforeAction appends a callback before actions. See Callback for parameter details.
Use the before callback to execute necessary logic before executing an action, the implementation could completely override the behavior of the action.
The chain of "before" callbacks execution interrupts when the non-nil result is returned. It's anticipated that before filters are often used to prevent from execution certain operations or queries.
AdminController := actioncontroller.New(func(c *actioncontroller.C) { c.AppendBeforeAction(func(ctx *actioncontroller.Context) actioncontroller.Result { if !isAuthorized(ctx) { return actionview.ContentResult(nil, errors.New("forbidden")) } return nil }) })
func (*C) AroundAction ¶
func (c *C) AroundAction(cb CallbackAround, only ...string)
func (*C) BeforeAction ¶
func (*C) Create ¶
func (c *C) Create(a ActionFunc)
func (*C) Destroy ¶
func (c *C) Destroy(a ActionFunc)
func (*C) Index ¶
func (c *C) Index(a ActionFunc)
func (*C) Show ¶
func (c *C) Show(a ActionFunc)
func (*C) Update ¶
func (c *C) Update(a ActionFunc)
type CallbackAround ¶
type Constraints ¶
type Constraints struct { Request *StrongParameters Response *StrongParameters Match Matcher }
type Context ¶
type Context struct { context.Context Params Parameters Selection []QueryAttribute }
type ErrActionNotFound ¶
type ErrActionNotFound struct {
ActionName string
}
ErrActionNotFound is returned when a non-existing action is triggered.
func (ErrActionNotFound) Error ¶
func (e ErrActionNotFound) Error() string
Error returns a string representation of the error.
type Mapper ¶
type Mapper interface { Resources(AbstractModel, AbstractController) // Match matches path to an action. Match(via, path string, action Action, constraints ...Constraints) Map() (http.Handler, error) }
type NamedAction ¶
type NamedAction struct { Name string Constraints Constraints ActionFunc }
func (*NamedAction) ActionConstraints ¶
func (a *NamedAction) ActionConstraints() Constraints
func (*NamedAction) ActionName ¶
func (a *NamedAction) ActionName() string
type Parameters ¶
type Parameters activesupport.Hash
func (Parameters) Get ¶
func (p Parameters) Get(key string) Parameters
type QueryAttribute ¶
type QueryAttribute struct { AttributeName string NestedAttributes []QueryAttribute }
func (QueryAttribute) NestedAttributeNames ¶
func (qa QueryAttribute) NestedAttributeNames() []string
type StrongParameters ¶
type StrongParameters struct {
Attributes []activerecord.Attribute
}
func Require ¶
func Require(rel *activerecord.Relation) *StrongParameters
func (*StrongParameters) Permit ¶
func (p *StrongParameters) Permit(names ...string) *StrongParameters