zk

package
v0.0.0-...-f82c1dc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2017 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package zk provides functions for getting and putting data in a znode.

Index

Constants

View Source
const (
	PermRead   = int32(zk.PermRead)
	PermWrite  = int32(zk.PermWrite)
	PermCreate = int32(zk.PermCreate)
	PermDelete = int32(zk.PermDelete)
	PermAdmin  = int32(zk.PermAdmin)
	PermAll    = int32(zk.PermAll)
)

Permissions bits to be used for ACLs

View Source
const DefaultAddr = "127.0.0.1:2181"

DefaultAddr is the default address for zookeeper.

Variables

View Source
var (
	// ErrZnodeDoesNotExist is returned if the requested znode does not exist.
	ErrZnodeDoesNotExist = zk.ErrNoNode
	// ErrZnodeAlreadyExists is returned if a given znode already exists.
	ErrZnodeAlreadyExists = zk.ErrNodeExists
)

Functions

This section is empty.

Types

type ACL

type ACL struct {
	Perms  int32
	Scheme string
	ID     string
}

ACL defines permissions, a scheme and an ID.

func AuthACL

func AuthACL(perms int32) []ACL

AuthACL produces an ACL list containing a single ACL which uses the provided permissions, with the scheme "auth", and ID "", which is used by ZooKeeper to represent any authenticated user.

func DigestACL

func DigestACL(perms int32, user, password string) []ACL

DigestACL produces an ACL list containing a single ACL which uses the provided permissions, with the scheme "digest" and a digest generated for a given user / password.

func WorldACL

func WorldACL(perms int32) []ACL

WorldACL produces an ACL list containing a single ACL which uses the provided permissions, with the scheme "world", and ID "anyone", which is used by ZooKeeper to represent any user at all.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client exports the main API that users of this package will use

func New

func New(config Config) (*Client, error)

New creates a new zookeeper Client.

func (*Client) Children

func (c *Client) Children(path string) ([]string, error)

Children returns the child znodes for this path.

func (*Client) Close

func (c *Client) Close() error

Close terminates the zk Client connection.

func (*Client) Create

func (c *Client) Create(path string, value []byte, acls []ACL) error

Create the znode.

func (*Client) CreateAll

func (c *Client) CreateAll(path string, value []byte, acls []ACL) error

CreateAll znodes for the path, including parents if necessary. value is only put into the last znode child.

func (*Client) CreateEphemeral

func (c *Client) CreateEphemeral(path string, value []byte, acls []ACL) error

CreateEphemeral creates an ephemeral znode.

func (*Client) CreateEphemeralSequential

func (c *Client) CreateEphemeralSequential(path string, value []byte, acls []ACL) (string, error)

CreateEphemeralSequential creates an ephemeral, sequential znode

func (*Client) CreateSequential

func (c *Client) CreateSequential(path string, value []byte, acls []ACL) (string, error)

CreateSequential creates a sequential znode.

func (*Client) DefaultACL

func (c *Client) DefaultACL(perms int32) []ACL

DefaultACL returns a slice with a single ACL of the given perms and default ID DefaultACL produces an ACL list containing a single ACL which uses the provided permissions and the default SchemeID passed through client config.

func (*Client) Delete

func (c *Client) Delete(path string) error

Delete removes the znode.

func (*Client) Exists

func (c *Client) Exists(path string) (bool, error)

Exists returns whether a znode exists.

func (*Client) Get

func (c *Client) Get(path string) ([]byte, error)

Get returns the data in the znode.

func (*Client) Put

func (c *Client) Put(path string, value []byte) error

Put places the data in the znode.

type Config

type Config struct {
	// Address for zookeeper, an empty string will use DefaultAddr
	Addr string

	// If specified, all paths for the Client will be prefixed by this
	BasePath string

	// Authentication info for the connection
	Auth *SchemeAuth

	// Default ID to be used for Client.DefaultACL function
	DefaultID *SchemeID

	// A logger for the client
	Logger Logger
}

Config defines the default parameters for zookeeper setup.

type Logger

type Logger interface {
	Printf(string, ...interface{})
}

Logger is used for debugging purposes

type SchemeAuth

type SchemeAuth struct {
	Scheme string
	Auth   string
}

SchemeAuth composes scheme and auth

func ParseSchemeAuth

func ParseSchemeAuth(schemeAuth string) (*SchemeAuth, error)

ParseSchemeAuth parses input such as "scheme:auth"

type SchemeID

type SchemeID struct {
	Scheme string
	ID     string
}

SchemeID composes a scheme and id

func ParseSchemeID

func ParseSchemeID(schemeID string) (*SchemeID, error)

ParseSchemeID parses input such as "scheme:id"

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL