本文整理汇总了Golang中github.com/dcjones/doozer.Conn.Set方法的典型用法代码示例。如果您正苦于以下问题:Golang Conn.Set方法的具体用法?Golang Conn.Set怎么用?Golang Conn.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/dcjones/doozer.Conn
的用法示例。
在下文中一共展示了Conn.Set方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例2: activate
func activate(st *store.Store, self string, c *doozer.Conn) int64 {
rev, _ := st.Snap()
for _, base := range store.Getdir(st, calDir) {
p := calDir + "/" + base
v, rev := st.Get(p)
if rev != store.Dir && v[0] == "" {
seqn, err := c.Set(p, rev, []byte(self))
if err != nil {
log.Println(err)
continue
}
return seqn
}
}
for {
ch, err := st.Wait(calGlob, rev+1)
if err != nil {
panic(err)
}
ev, ok := <-ch
if !ok {
panic(io.EOF)
}
rev = ev.Rev
// TODO ev.IsEmpty()
if ev.IsSet() && ev.Body == "" {
seqn, err := c.Set(ev.Path, ev.Rev, []byte(self))
if err != nil {
log.Println(err)
continue
}
return seqn
} else if ev.IsSet() && ev.Body == self {
return ev.Seqn
}
}
return 0
}
示例3: setC
func setC(cl *doozer.Conn, path, body string, rev int64) {
_, err := cl.Set(path, rev, []byte(body))
if err != nil {
panic(err)
}
}