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