当前位置: 首页>>代码示例>>Golang>>正文


Golang Environment.HandleEvent方法代码示例

本文整理汇总了Golang中github.com/cloudwan/gohan/extension.Environment.HandleEvent方法的典型用法代码示例。如果您正苦于以下问题:Golang Environment.HandleEvent方法的具体用法?Golang Environment.HandleEvent怎么用?Golang Environment.HandleEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/cloudwan/gohan/extension.Environment的用法示例。


在下文中一共展示了Environment.HandleEvent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: runExtensionOnSync

//Run extension on sync
func runExtensionOnSync(server *Server, response *gohan_sync.Event, env extension.Environment) {
	lockKey := lockPath + response.Key
	err := server.sync.Lock(lockKey, false)
	if err != nil {
		return
	}
	defer func() {
		server.sync.Unlock(lockKey)
	}()
	tx, err := server.db.Begin()
	defer tx.Close()
	context := map[string]interface{}{
		"transaction": tx,
		"action":      response.Action,
		"data":        response.Data,
		"key":         response.Key,
	}
	if err != nil {
		return
	}
	if err := env.HandleEvent("notification", context); err != nil {
		log.Warning(fmt.Sprintf("extension error: %s", err))
		return
	}
	err = tx.Commit()
	if err != nil {
		log.Error(fmt.Sprintf("commit error : %s", err))
		return
	}
	return
}
开发者ID:gitter-badger,项目名称:gohan,代码行数:32,代码来源:sync.go

示例2: runExtensionOnSync

//Run extension on sync
func runExtensionOnSync(server *Server, response *gohan_sync.Event, env extension.Environment) {
	context := map[string]interface{}{
		"action": response.Action,
		"data":   response.Data,
		"key":    response.Key,
	}
	if err := env.HandleEvent("notification", context); err != nil {
		log.Warning(fmt.Sprintf("extension error: %s", err))
		return
	}
	return
}
开发者ID:cloudwan,项目名称:gohan,代码行数:13,代码来源:sync_watch.go

示例3: handleEvent

func handleEvent(context middleware.Context, environment extension.Environment, event string) error {
	if err := environment.HandleEvent(event, context); err != nil {
		return fmt.Errorf("extension error: %s", err)
	}
	exceptionInfoRaw, ok := context["exception"]
	if !ok {
		return nil
	}
	exceptionInfo, ok := exceptionInfoRaw.(map[string]interface{})
	if !ok {
		return fmt.Errorf("extension returned invalid error information")
	}
	exceptionMessage := context["exception_message"]
	return ExtensionError{fmt.Errorf("%v", exceptionMessage), exceptionInfo}
}
开发者ID:gitter-badger,项目名称:gohan,代码行数:15,代码来源:resource_management.go

示例4:

						  context.networks = gohan_db_list(context.transaction, 'network', {});
						  gohan_db_delete(context.transaction, 'network', 'test1');
						  context.networks2 = gohan_db_list(context.transaction, 'network', {});
						});`,
						"path": ".*",
					})
					Expect(err).ToNot(HaveOccurred())
					extensions := []*schema.Extension{extension}
					env := otto.NewEnvironment(testDB, &middleware.FakeIdentity{})
					env.LoadExtensionsForPath(extensions, "test_path")

					context := map[string]interface{}{
						"id":          "test",
						"transaction": tx,
					}
					Expect(env.HandleEvent("test_event", context)).To(Succeed())
					Expect(context["network"]).ToNot(BeNil())
					Expect(context["networks"]).ToNot(BeNil())
				})
			})

			Context("When given no transaction", func() {
				It("Correctly handles CRUD operations", func() {
					tx, err := testDB.Begin()
					defer tx.Commit()

					extension, err := schema.NewExtension(map[string]interface{}{
						"id": "test_extension",
						"code": `
						gohan_register_handler("test_event", function(context){
						  gohan_db_create(context.transaction,
开发者ID:nati,项目名称:gohan,代码行数:31,代码来源:otto_test.go


注:本文中的github.com/cloudwan/gohan/extension.Environment.HandleEvent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。