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


Golang Conn.Del方法代码示例

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


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

示例1: elect

// Elect chooses a seed node, and returns a connection to a cal.
// If this process is the seed, returns nil.
func elect(name, id, laddr string, b *doozer.Conn) *doozer.Conn {
	// advertise our presence, since we might become a cal
	nspath := "/ctl/ns/" + name + "/" + id
	r, err := b.Set(nspath, 0, []byte(laddr))
	if err != nil {
		panic(err)
	}

	// fight to be the seed
	_, err = b.Set("/ctl/boot/"+name, 0, []byte(id))
	if err, ok := err.(*doozer.Error); ok && err.Err == doozer.ErrOldRev {
		// we lost, lookup addresses again
		cl := lookupAndAttach(b, name)
		if cl == nil {
			panic("failed to attach after losing election")
		}

		// also delete our entry, since we're not officially a cal yet.
		// it gets set again in peer.Main when we become a cal.
		err := b.Del(nspath, r)
		if err != nil {
			panic(err)
		}

		return cl
	} else if err != nil {
		panic(err)
	}

	return nil // we are the seed node -- don't attach
}
开发者ID:zyxar,项目名称:doozerd,代码行数:33,代码来源:boot.go

示例2: writer

func writer(
	conn *doozer.Conn,
	root string,
	entryc chan *journal.Entry,
	errc chan error,
) {
	for entry := range entryc {
		if strings.HasPrefix(entry.Path, root) &&
			!strings.HasPrefix(entry.Path, journal.InternalPrefix) {

			var err error
			switch entry.Op {
			case journal.OpSet:
				_, e := conn.Set(entry.Path, -1, entry.Value)
				if e != nil {
					err = fmt.Errorf("unable setting '%s' to '%s'", entry.Path, string(entry.Value))
				}
			case journal.OpDel:
				e := conn.Del(entry.Path, -1)
				if e != nil {
					err = fmt.Errorf("unable deleting '%s'", entry.Path)
				}
			default:
				err = fmt.Errorf("unknown operation %s", entry.Op)
			}

			if err != nil {
				errc <- err
				return
			}

			b, err := journal.Marshal(entry)
			if err != nil {
				continue
			}
			fmt.Println(string(b))
		}
	}
}
开发者ID:soundcloud,项目名称:doozer-journal,代码行数:39,代码来源:replicate.go


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