コード例 #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
ファイル: example_test.go プロジェクト: kazukgw/takobot
func Example() {
	ag := &ActionGroup{}
	ctx := &Context{&ActionGroup{}}
	coa.Exec(ag, ctx)
	// Output:
	// 1
	// 2
	// do
	// 3
}
コード例 #4
0
ファイル: handlerbuilder.go プロジェクト: kazukgw/takobot
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
ファイル: gin_handlerbuilder.go プロジェクト: kazukgw/takobot
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_nestedAction() {
	ag := &NestGroup{}
	ctx := &Context{ag}
	coa.Exec(ag, ctx)
	// Output:
	// 1
	// 2
	// nested
	// 3
	// 1
	// do
	// 2
}
コード例 #7
0
ファイル: context.go プロジェクト: kazukgw/takobot
func (ctx *Context) Exec() error {
	return coa.Exec(ctx.ActionGroup(), ctx)
}
コード例 #8
0
ファイル: msghandlecontext.go プロジェクト: kazukgw/takobot
func (ctx *MsgContext) Exec() error {
	return coa.Exec(ctx.ActionGroup(), coa.Context(ctx))
}