コード例 #1
0
ファイル: zkutils_test.go プロジェクト: koofr/go-zkutils
			zz, session, err := zk.Dial("localhost:"+strconv.Itoa(port), 5e9)
			Expect(err).NotTo(HaveOccurred())

			Expect((<-session).State).To(Equal(zk.STATE_CONNECTED))

			z = zz
		})

		AfterEach(func() {
			z.Close()
			s.Stop()
		})

		It("should ensure path", func() {
			perm := zk.WorldACL(zk.PERM_ALL)

			stat, err := z.Exists("/part1")
			Expect(err).NotTo(HaveOccurred())
			Expect(stat).To(BeNil())

			err = EnsurePath(z, []string{"part1"}, perm)
			Expect(err).NotTo(HaveOccurred())

			stat, err = z.Exists("/part1")
			Expect(err).NotTo(HaveOccurred())
			Expect(stat).NotTo(BeNil())

			err = EnsurePath(z, []string{"part1"}, perm)
			Expect(err).NotTo(HaveOccurred())
コード例 #2
0
package serviceregistry

import (
	"fmt"
	"github.com/koofr/go-zkutils"
	zk "github.com/koofr/gozk"
	"sync"
	"time"
)

var ZK_PERM = zk.WorldACL(zk.PERM_ALL)

type entry struct {
	service  string
	protocol string
	server   string
}

type ZkRegistry struct {
	zkServers    string
	zk           *zk.Conn
	zkSession    <-chan zk.Event
	zkMutex      sync.RWMutex
	closed       bool
	entries      []*entry
	entriesMutex sync.RWMutex
}

func NewZkRegistry(zkServers string) (r *ZkRegistry, err error) {
	r = &ZkRegistry{
		zkServers: zkServers,