Example #1
0
func Example_recover() {
	ag := &RecoverableGroup{}
	ctx := &Context{ag}
	coa.Exec(ag, ctx)
	// Output:
	// 1
	// 2
	// recover
}
Example #2
0
func Example_errorHandle() {
	ag := &ErrorGroup{}
	ctx := &Context{ag}
	coa.Exec(ag, ctx)
	// Output:
	// 1
	// 2
	// error!
	// post exec
}
Example #3
0
func Example() {
	ag := &ActionGroup{}
	ctx := &Context{&ActionGroup{}}
	coa.Exec(ag, ctx)
	// Output:
	// 1
	// 2
	// do
	// 3
}
Example #4
0
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)
	}
}
Example #5
0
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)
	}
}
Example #6
0
func Example_hook() {
	ag := &HookGroup{}
	ctx := &Context{ag}
	coa.Exec(ag, ctx)
	// Output:
	// PreExec!
	// 1
	// 2
	// do
	// 3
	// PostExec!
}
Example #7
0
func Example_nestedAction() {
	ag := &NestGroup{}
	ctx := &Context{ag}
	coa.Exec(ag, ctx)
	// Output:
	// 1
	// 2
	// nested
	// 3
	// 1
	// do
	// 2
}
Example #8
0
func Example_repeat() {
	ag := &RepeatableGroup{}
	ctx := &Context{ag}
	coa.Exec(ag, ctx)
	// Output:
	// 1
	// 2
	// do
	// 3
	// 1
	// 2
	// do
	// 3
	// 1
	// 2
	// do
	// 3
}