當前位置: 首頁>>代碼示例>>Golang>>正文


Golang extension.Environment類代碼示例

本文整理匯總了Golang中github.com/cloudwan/gohan/extension.Environment的典型用法代碼示例。如果您正苦於以下問題:Golang Environment類的具體用法?Golang Environment怎麽用?Golang Environment使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Environment類的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:

				Expect(context).To(HaveKeyWithValue("resp", HaveKeyWithValue("status", "err")))
				Expect(context).To(HaveKeyWithValue("resp", HaveKey("error")))
			})
		})
	})

	Describe("Using gohan database manipulation builtins", func() {
		var (
			adminAuth     schema.Authorization
			memberAuth    schema.Authorization
			auth          schema.Authorization
			context       middleware.Context
			schemaID      string
			path          string
			action        string
			currentSchema *schema.Schema
			extensions    []*schema.Extension
			env           extension.Environment
			events        map[string]string

			network1 map[string]interface{}
			network2 map[string]interface{}
			subnet1  map[string]interface{}
		)

		BeforeEach(func() {
			adminAuth = schema.NewAuthorization(adminTenantID, "admin", adminTokenID, []string{"admin"}, nil)
			memberAuth = schema.NewAuthorization(memberTenantID, "member", memberTokenID, []string{"_member_"}, nil)
			auth = adminAuth

			context = middleware.Context{}
開發者ID:nati,項目名稱:gohan,代碼行數:31,代碼來源:otto_test.go


注:本文中的github.com/cloudwan/gohan/extension.Environment類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。