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


Golang Resource.Path方法代码示例

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


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

示例1: logEvent

func (tl *transactionEventLogger) logEvent(eventType string, resource *schema.Resource, version int64) error {
	schemaManager := schema.GetManager()
	eventSchema, ok := schemaManager.Schema("event")
	if !ok {
		return fmt.Errorf("event schema not found")
	}

	if resource.Schema().Metadata["nosync"] == true {
		log.Debug("skipping event logging for schema: %s", resource.Schema().ID)
		return nil
	}
	body, err := resource.JSONString()
	if err != nil {
		return fmt.Errorf("Error during event resource deserialisation: %s", err.Error())
	}
	eventResource, err := schema.NewResource(eventSchema, map[string]interface{}{
		"type":      eventType,
		"path":      resource.Path(),
		"version":   version,
		"body":      body,
		"timestamp": int64(time.Now().Unix()),
	})
	tl.eventLogged = true
	return tl.Transaction.Create(eventResource)
}
开发者ID:vozhyk-,项目名称:gohan,代码行数:25,代码来源:sync.go

示例2:

			Expect(err).ToNot(HaveOccurred())
			Expect(tx.Create(networkResource)).To(Succeed())
			Expect(tx.Commit()).To(Succeed())
		})

		Describe("Updating state", func() {
			Context("Invoked correctly", func() {
				It("Should work", func() {
					possibleEvent = gohan_sync.Event{
						Action: "this is ignored here",
						Data: map[string]interface{}{
							"version": float64(1),
							"error":   "",
							"state":   "Ni malvarmetas",
						},
						Key: statePrefix + networkResource.Path(),
					}
					Expect(srv.StateUpdate(&possibleEvent, server)).To(Succeed())

					tx, err := wrappedTestDB.Begin()
					Expect(err).ToNot(HaveOccurred())
					defer tx.Close()
					afterState, err := tx.StateFetch(networkSchema, networkResource.ID(), nil)
					Expect(err).ToNot(HaveOccurred())
					Expect(tx.Commit()).To(Succeed())
					Expect(afterState.ConfigVersion).To(Equal(int64(1)))
					Expect(afterState.StateVersion).To(Equal(int64(1)))
					Expect(afterState.State).To(Equal("Ni malvarmetas"))
					Expect(afterState.Error).To(Equal(""))
					Expect(afterState.Monitoring).To(Equal(""))
				})
开发者ID:masaki-saeki,项目名称:gohan,代码行数:31,代码来源:server_test.go

示例3:

				"shared":            false,
				"route_targets":     []string{"1000:10000", "2000:20000"},
				"providor_networks": map[string]interface{}{"segmentation_id": 10, "segmentation_type": "vlan"}}
			networkResource2, err = manager.LoadResource("network", network2)
			Expect(err).ToNot(HaveOccurred())

			subnet := map[string]interface{}{
				"id":          "subnetRed",
				"name":        "SubnetRed",
				"description": "A crimson subnet",
				"tenant_id":   "red",
				"cidr":        "10.0.0.0/24"}
			subnetResource, err = manager.LoadResource("subnet", subnet)
			Expect(err).ToNot(HaveOccurred())
			subnetResource.SetParentID("networkRed")
			Expect(subnetResource.Path()).To(Equal("/v2.0/subnets/subnetRed"))

			server := map[string]interface{}{
				"id":          "serverRed",
				"name":        "serverRed",
				"tenant_id":   "red",
				"network_id":  "networkRed",
				"description": "red server",
				"cidr":        "10.0.0.0/24"}
			serverResource, err = manager.LoadResource("server", server)
			Expect(err).ToNot(HaveOccurred())
		})

		JustBeforeEach(func() {
			os.Remove(conn)
			dataStore, err = db.ConnectDB(dbType, conn, db.DefaultMaxOpenConn)
开发者ID:vozhyk-,项目名称:gohan,代码行数:31,代码来源:db_test.go


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