本文整理汇总了Golang中github.com/contiv/volplugin/db.Entity.Path方法的典型用法代码示例。如果您正苦于以下问题:Golang Entity.Path方法的具体用法?Golang Entity.Path怎么用?Golang Entity.Path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/contiv/volplugin/db.Entity
的用法示例。
在下文中一共展示了Entity.Path方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: setKey
func setKey(value db.Entity) {
path, err := value.Path()
if err != nil {
panic(err)
}
content, err := jsonio.Write(value)
if err != nil {
panic(err)
}
switch Driver {
case "etcd":
client, err := getEtcdClient()
if err != nil {
panic(err)
}
if _, err := client.Set(context.Background(), fmt.Sprintf("/volplugin/%v", path), string(content), nil); err != nil {
panic(err)
}
case "consul":
client, err := getConsulClient()
if err != nil {
panic(err)
}
if _, err := client.KV().Put(&api.KVPair{Key: fmt.Sprintf("volplugin/%v", path), Value: content}, nil); err != nil {
panic(err)
}
}
}
示例2: Set
// Set takes the object and commits it to the database.
func (c *Client) Set(obj db.Entity) error {
if err := obj.Validate(); err != nil {
return err
}
if obj.Hooks().PreSet != nil {
if err := obj.Hooks().PreSet(c, obj); err != nil {
return errors.EtcdToErrored(err)
}
}
content, err := jsonio.Write(obj)
if err != nil {
return err
}
path, err := obj.Path()
if err != nil {
return err
}
if _, err := c.client.Set(context.Background(), c.qualified(path), string(content), nil); err != nil {
return errors.EtcdToErrored(err)
}
if obj.Hooks().PostSet != nil {
if err := obj.Hooks().PostSet(c, obj); err != nil {
return errors.EtcdToErrored(err)
}
}
return nil
}
示例3: Get
// Get retrieves the item from etcd's key/value store and then populates obj with its data.
func (c *Client) Get(obj db.Entity) error {
if obj.Hooks().PreGet != nil {
if err := obj.Hooks().PreGet(c, obj); err != nil {
return errors.EtcdToErrored(err)
}
}
path, err := obj.Path()
if err != nil {
return err
}
resp, err := c.client.Get(context.Background(), c.qualified(path), nil)
if err != nil {
return errors.EtcdToErrored(err)
}
if err := jsonio.Read(obj, []byte(resp.Node.Value)); err != nil {
return err
}
if err := obj.SetKey(c.trimPath(resp.Node.Key)); err != nil {
return err
}
if obj.Hooks().PostGet != nil {
if err := obj.Hooks().PostGet(c, obj); err != nil {
return errors.EtcdToErrored(err)
}
}
return obj.Validate()
}
示例4: WatchStop
// WatchStop stops a watch.
func (c *Client) WatchStop(obj db.Entity) error {
path, err := obj.Path()
if err != nil {
return err
}
return helpers.WatchStop(c, path, c.watchers, &c.watcherMutex)
}
示例5: WatchStop
// WatchStop stops a watch for a given object.
func (c *Client) WatchStop(obj db.Entity) error {
path, err := obj.Path()
if err != nil {
return err
}
return c.watchStopPath(path)
}
示例6: Watch
// Watch watches a given object for changes.
func (c *Client) Watch(obj db.Entity) (chan db.Entity, chan error) {
path, err := obj.Path()
if err != nil {
errChan := make(chan error, 1)
errChan <- err
return nil, errChan
}
return helpers.WrapWatch(c, obj, path, false, c.watchers, &c.watcherMutex, c.startWatch)
}
示例7: Watch
// Watch watches a given object for changes.
func (c *Client) Watch(obj db.Entity) (chan db.Entity, chan error) {
path, err := obj.Path()
if err != nil {
errChan := make(chan error, 1)
errChan <- err
return make(chan db.Entity), errChan
}
return c.watchPath(obj, path, false)
}
示例8: setKey
func setKey(value db.Entity) {
client, err := getEtcdClient()
if err != nil {
panic(err)
}
path, err := value.Path()
if err != nil {
panic(err)
}
content, err := jsonio.Write(value)
if err != nil {
panic(err)
}
if _, err := client.Set(context.Background(), fmt.Sprintf("/volplugin/%v", path), string(content), nil); err != nil {
panic(err)
}
}
示例9: Delete
// Delete removes the object from the store.
func (c *Client) Delete(obj db.Entity) error {
if obj.Hooks().PreDelete != nil {
if err := obj.Hooks().PreDelete(c, obj); err != nil {
return errors.EtcdToErrored(err)
}
}
path, err := obj.Path()
if err != nil {
return err
}
if _, err := c.client.Delete(context.Background(), c.qualified(path), nil); err != nil {
return errors.EtcdToErrored(err)
}
if obj.Hooks().PostDelete != nil {
if err := obj.Hooks().PostDelete(c, obj); err != nil {
return errors.EtcdToErrored(err)
}
}
return nil
}