func Example_recover() { ag := &RecoverableGroup{} ctx := &Context{ag} coa.Exec(ag, ctx) // Output: // 1 // 2 // recover }
func Example_errorHandle() { ag := &ErrorGroup{} ctx := &Context{ag} coa.Exec(ag, ctx) // Output: // 1 // 2 // error! // post exec }
func Example() { ag := &ActionGroup{} ctx := &Context{&ActionGroup{}} coa.Exec(ag, ctx) // Output: // 1 // 2 // do // 3 }
func (ab *HandlerBuilder) Build(zeroActionGroup interface{}) func(http.ResponseWriter, *http.Request) { actionType := reflect.TypeOf(zeroActionGroup) if _, ok := reflect.New(actionType).Interface().(coa.ActionGroup); !ok { panic(actionType.String() + " dose not implement coa.ActionGroup interface") } return func(w http.ResponseWriter, r *http.Request) { ag := reflect.New(actionType).Interface().(coa.ActionGroup) ctx := ab.NewContext(w, r, ag) coa.Exec(ag, ctx) } }
func (ab *GinHandlerBuilder) Build(zeroActionGroup interface{}) func(*gin.Context) { actionType := reflect.TypeOf(zeroActionGroup) if _, ok := reflect.New(actionType).Interface().(coa.ActionGroup); !ok { panic(actionType.String() + " dose not implement Action interface") } return func(c *gin.Context) { ag := reflect.New(actionType).Interface().(coa.ActionGroup) ctx := ab.NewContext(c, ag) coa.Exec(ag, ctx) } }
func Example_nestedAction() { ag := &NestGroup{} ctx := &Context{ag} coa.Exec(ag, ctx) // Output: // 1 // 2 // nested // 3 // 1 // do // 2 }
func (ctx *Context) Exec() error { return coa.Exec(ctx.ActionGroup(), ctx) }
func (ctx *MsgContext) Exec() error { return coa.Exec(ctx.ActionGroup(), coa.Context(ctx)) }