go-etcd: github.com/coreos/go-etcd/etcd Index | Files

package etcd

import "github.com/coreos/go-etcd/etcd"

Index

Package Files

add_child.go client.go cluster.go compare_and_delete.go compare_and_swap.go debug.go delete.go error.go get.go member.go options.go requests.go response.generated.go response.go set_update_create.go shuffle.go version.go watch.go

Constants

const (
    // Using strings rather than iota because the consistency level
    // could be persisted to disk, so it'd be better to use
    // human-readable values.
    STRONG_CONSISTENCY = "STRONG"
    WEAK_CONSISTENCY   = "WEAK"
)

See SetConsistency for how to use these constants.

const (
    ErrCodeEtcdNotReachable    = 501
    ErrCodeUnhandledHTTPStatus = 502
)

Variables

var (
    VALID_GET_OPTIONS = validOptions{
        "recursive": reflect.Bool,
        "quorum":    reflect.Bool,
        "sorted":    reflect.Bool,
        "wait":      reflect.Bool,
        "waitIndex": reflect.Uint64,
    }

    VALID_PUT_OPTIONS = validOptions{
        "prevValue": reflect.String,
        "prevIndex": reflect.Uint64,
        "prevExist": reflect.Bool,
        "dir":       reflect.Bool,
    }

    VALID_POST_OPTIONS = validOptions{}

    VALID_DELETE_OPTIONS = validOptions{
        "recursive": reflect.Bool,
        "dir":       reflect.Bool,
        "prevValue": reflect.String,
        "prevIndex": reflect.Uint64,
    }
)

Valid options for GET, PUT, POST, DELETE Using CAPITALIZED_UNDERSCORE to emphasize that these values are meant to be used as constants.

var (
    ErrRequestCancelled = errors.New("sending request is cancelled")
)

Errors introduced by handling requests

var (
    ErrWatchStoppedByUser = errors.New("Watch stopped by the user via stop channel")
)

Errors introduced by the Watch command.

func DefaultCheckRetry Uses

func DefaultCheckRetry(cluster *Cluster, numReqs int, lastResp http.Response,
    err error) error

DefaultCheckRetry defines the retrying behaviour for bad HTTP requests If we have retried 2 * machine number, stop retrying. If status code is InternalServerError, sleep for 200ms.

func GetLogger Uses

func GetLogger() *log.Logger

func SetLogger Uses

func SetLogger(l *log.Logger)

type Client Uses

type Client struct {

    // CheckRetry can be used to control the policy for failed requests
    // and modify the cluster if needed.
    // The client calls it before sending requests again, and
    // stops retrying if CheckRetry returns some error. The cases that
    // this function needs to handle include no response and unexpected
    // http status code of response.
    // If CheckRetry is nil, client will call the default one
    // `DefaultCheckRetry`.
    // Argument cluster is the etcd.Cluster object that these requests have been made on.
    // Argument numReqs is the number of http.Requests that have been made so far.
    // Argument lastResp is the http.Responses from the last request.
    // Argument err is the reason of the failure.
    CheckRetry func(cluster *Cluster, numReqs int,
        lastResp http.Response, err error) error
    // contains filtered or unexported fields
}

func NewClient Uses

func NewClient(machines []string) *Client

NewClient create a basic client that is configured to be used with the given machine list.

func NewClientFromFile Uses

func NewClientFromFile(fpath string) (*Client, error)

NewClientFromFile creates a client from a given file path. The given file is expected to use the JSON format.

func NewClientFromReader Uses

func NewClientFromReader(reader io.Reader) (*Client, error)

NewClientFromReader creates a Client configured from a given reader. The configuration is expected to use the JSON format.

func NewTLSClient Uses

func NewTLSClient(machines []string, cert, key, caCert string) (*Client, error)

NewTLSClient create a basic client with TLS configuration

func (*Client) AddChild Uses

func (c *Client) AddChild(key string, value string, ttl uint64) (*Response, error)

Add a new file with a random etcd-generated key under the given path.

func (*Client) AddChildDir Uses

func (c *Client) AddChildDir(key string, ttl uint64) (*Response, error)

Add a new directory with a random etcd-generated key under the given path.

func (*Client) AddRootCA Uses

func (c *Client) AddRootCA(caCert string) error

AddRootCA adds a root CA cert for the etcd client

func (*Client) Close Uses

func (c *Client) Close()

func (*Client) CloseCURL Uses

func (c *Client) CloseCURL()

func (*Client) CompareAndDelete Uses

func (c *Client) CompareAndDelete(key string, prevValue string, prevIndex uint64) (*Response, error)

func (*Client) CompareAndSwap Uses

func (c *Client) CompareAndSwap(key string, value string, ttl uint64,
    prevValue string, prevIndex uint64) (*Response, error)

func (*Client) Create Uses

func (c *Client) Create(key string, value string, ttl uint64) (*Response, error)

Create creates a file with the given value under the given key. It succeeds only if the given key does not yet exist.

func (*Client) CreateDir Uses

func (c *Client) CreateDir(key string, ttl uint64) (*Response, error)

CreateDir creates a directory. It succeeds only if the given key does not yet exist.

func (*Client) CreateInOrder Uses

func (c *Client) CreateInOrder(dir string, value string, ttl uint64) (*Response, error)

CreateInOrder creates a file with a key that's guaranteed to be higher than other keys in the given directory. It is useful for creating queues.

func (*Client) DefaultDial Uses

func (c *Client) DefaultDial(network, addr string) (net.Conn, error)

DefaultDial attempts to open a TCP connection to the provided address, explicitly enabling keep-alives with a one-second interval.

func (*Client) Delete Uses

func (c *Client) Delete(key string, recursive bool) (*Response, error)

Delete deletes the given key.

When recursive set to false, if the key points to a directory the method will fail.

When recursive set to true, if the key points to a file, the file will be deleted; if the key points to a directory, then everything under the directory (including all child directories) will be deleted.

func (*Client) DeleteDir Uses

func (c *Client) DeleteDir(key string) (*Response, error)

DeleteDir deletes an empty directory or a key value pair

func (*Client) Get Uses

func (c *Client) Get(key string, sort, recursive bool) (*Response, error)

Get gets the file or directory associated with the given key. If the key points to a directory, files and directories under it will be returned in sorted or unsorted order, depending on the sort flag. If recursive is set to false, contents under child directories will not be returned. If recursive is set to true, all the contents will be returned.

func (*Client) GetCluster Uses

func (c *Client) GetCluster() []string

func (*Client) MarshalJSON Uses

func (c *Client) MarshalJSON() ([]byte, error)

MarshalJSON implements the Marshaller interface as defined by the standard JSON package.

func (*Client) OpenCURL Uses

func (c *Client) OpenCURL()

func (*Client) RawCompareAndDelete Uses

func (c *Client) RawCompareAndDelete(key string, prevValue string, prevIndex uint64) (*RawResponse, error)

func (*Client) RawCompareAndSwap Uses

func (c *Client) RawCompareAndSwap(key string, value string, ttl uint64,
    prevValue string, prevIndex uint64) (*RawResponse, error)

func (*Client) RawCreate Uses

func (c *Client) RawCreate(key string, value string, ttl uint64) (*RawResponse, error)

func (*Client) RawCreateDir Uses

func (c *Client) RawCreateDir(key string, ttl uint64) (*RawResponse, error)

func (*Client) RawCreateInOrder Uses

func (c *Client) RawCreateInOrder(dir string, value string, ttl uint64) (*RawResponse, error)

func (*Client) RawDelete Uses

func (c *Client) RawDelete(key string, recursive bool, dir bool) (*RawResponse, error)

func (*Client) RawGet Uses

func (c *Client) RawGet(key string, sort, recursive bool) (*RawResponse, error)

func (*Client) RawSet Uses

func (c *Client) RawSet(key string, value string, ttl uint64) (*RawResponse, error)

func (*Client) RawSetDir Uses

func (c *Client) RawSetDir(key string, ttl uint64) (*RawResponse, error)

func (*Client) RawUpdate Uses

func (c *Client) RawUpdate(key string, value string, ttl uint64) (*RawResponse, error)

func (*Client) RawUpdateDir Uses

func (c *Client) RawUpdateDir(key string, ttl uint64) (*RawResponse, error)

func (*Client) RawWatch Uses

func (c *Client) RawWatch(prefix string, waitIndex uint64, recursive bool,
    receiver chan *RawResponse, stop chan bool) (*RawResponse, error)

func (*Client) RecvCURL Uses

func (c *Client) RecvCURL() string

func (*Client) SendRequest Uses

func (c *Client) SendRequest(rr *RawRequest) (*RawResponse, error)

SendRequest sends a HTTP request and returns a Response as defined by etcd

func (*Client) Set Uses

func (c *Client) Set(key string, value string, ttl uint64) (*Response, error)

Set sets the given key to the given value. It will create a new key value pair or replace the old one. It will not replace a existing directory.

func (*Client) SetCluster Uses

func (c *Client) SetCluster(machines []string) bool

SetCluster updates cluster information using the given machine list.

func (*Client) SetConsistency Uses

func (c *Client) SetConsistency(consistency string) error

SetConsistency changes the consistency level of the client.

When consistency is set to STRONG_CONSISTENCY, all requests, including GET, are sent to the leader. This means that, assuming the absence of leader failures, GET requests are guaranteed to see the changes made by previous requests.

When consistency is set to WEAK_CONSISTENCY, other requests are still sent to the leader, but GET requests are sent to a random server from the server pool. This reduces the read load on the leader, but it's not guaranteed that the GET requests will see changes made by previous requests (they might have not yet been committed on non-leader servers).

func (*Client) SetCredentials Uses

func (c *Client) SetCredentials(username, password string)

func (*Client) SetDialTimeout Uses

func (c *Client) SetDialTimeout(d time.Duration)

Sets the DialTimeout value

func (*Client) SetDir Uses

func (c *Client) SetDir(key string, ttl uint64) (*Response, error)

SetDir sets the given key to a directory. It will create a new directory or replace the old key value pair by a directory. It will not replace a existing directory.

func (*Client) SetPersistence Uses

func (c *Client) SetPersistence(writer io.Writer)

SetPersistence sets a writer to which the config will be written every time it's changed.

func (*Client) SetTransport Uses

func (c *Client) SetTransport(tr *http.Transport)

Override the Client's HTTP Transport object

func (*Client) SyncCluster Uses

func (c *Client) SyncCluster() bool

SyncCluster updates the cluster information using the internal machine list. If no members are found, the intenral machine list is left untouched.

func (*Client) UnmarshalJSON Uses

func (c *Client) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the Unmarshaller interface as defined by the standard JSON package.

func (*Client) Update Uses

func (c *Client) Update(key string, value string, ttl uint64) (*Response, error)

Update updates the given key to the given value. It succeeds only if the given key already exists.

func (*Client) UpdateDir Uses

func (c *Client) UpdateDir(key string, ttl uint64) (*Response, error)

UpdateDir updates the given directory. It succeeds only if the given key already exists.

func (*Client) Watch Uses

func (c *Client) Watch(prefix string, waitIndex uint64, recursive bool,
    receiver chan *Response, stop chan bool) (*Response, error)

If recursive is set to true the watch returns the first change under the given prefix since the given index.

If recursive is set to false the watch returns the first change to the given key since the given index.

To watch for the latest change, set waitIndex = 0.

If a receiver channel is given, it will be a long-term watch. Watch will block at the channel. After someone receives the channel, it will go on to watch that prefix. If a stop channel is given, the client can close long-term watch using the stop channel.

type Cluster Uses

type Cluster struct {
    Leader   string   `json:"leader"`
    Machines []string `json:"machines"`
    // contains filtered or unexported fields
}

func NewCluster Uses

func NewCluster(machines []string) *Cluster

type Config Uses

type Config struct {
    CertFile    string        `json:"certFile"`
    KeyFile     string        `json:"keyFile"`
    CaCertFile  []string      `json:"caCertFiles"`
    DialTimeout time.Duration `json:"timeout"`
    Consistency string        `json:"consistency"`
}

type EtcdError Uses

type EtcdError struct {
    ErrorCode int    `json:"errorCode"`
    Message   string `json:"message"`
    Cause     string `json:"cause,omitempty"`
    Index     uint64 `json:"index"`
}

func (EtcdError) Error Uses

func (e EtcdError) Error() string

type Member Uses

type Member struct {
    ID         string   `json:"id"`
    Name       string   `json:"name"`
    PeerURLs   []string `json:"peerURLs"`
    ClientURLs []string `json:"clientURLs"`
}

type Node Uses

type Node struct {
    Key           string     `json:"key, omitempty"`
    Value         string     `json:"value,omitempty"`
    Dir           bool       `json:"dir,omitempty"`
    Expiration    *time.Time `json:"expiration,omitempty"`
    TTL           int64      `json:"ttl,omitempty"`
    Nodes         Nodes      `json:"nodes,omitempty"`
    ModifiedIndex uint64     `json:"modifiedIndex,omitempty"`
    CreatedIndex  uint64     `json:"createdIndex,omitempty"`
}

func (*Node) CodecDecodeSelf Uses

func (x *Node) CodecDecodeSelf(d *codec1978.Decoder)

func (*Node) CodecEncodeSelf Uses

func (x *Node) CodecEncodeSelf(e *codec1978.Encoder)

type Nodes Uses

type Nodes []*Node

func (*Nodes) CodecDecodeSelf Uses

func (x *Nodes) CodecDecodeSelf(d *codec1978.Decoder)

func (Nodes) CodecEncodeSelf Uses

func (x Nodes) CodecEncodeSelf(e *codec1978.Encoder)

func (Nodes) Len Uses

func (ns Nodes) Len() int

interfaces for sorting

func (Nodes) Less Uses

func (ns Nodes) Less(i, j int) bool

func (Nodes) Swap Uses

func (ns Nodes) Swap(i, j int)

type Options Uses

type Options map[string]interface{}

type RawRequest Uses

type RawRequest struct {
    Method       string
    RelativePath string
    Values       url.Values
    Cancel       <-chan bool
}

func NewRawRequest Uses

func NewRawRequest(method, relativePath string, values url.Values, cancel <-chan bool) *RawRequest

NewRawRequest returns a new RawRequest

type RawResponse Uses

type RawResponse struct {
    StatusCode int
    Body       []byte
    Header     http.Header
}

func (*RawResponse) CodecDecodeSelf Uses

func (x *RawResponse) CodecDecodeSelf(d *codec1978.Decoder)

func (*RawResponse) CodecEncodeSelf Uses

func (x *RawResponse) CodecEncodeSelf(e *codec1978.Encoder)

func (*RawResponse) Unmarshal Uses

func (rr *RawResponse) Unmarshal() (*Response, error)

Unmarshal parses RawResponse and stores the result in Response

type Response Uses

type Response struct {
    Action    string `json:"action"`
    Node      *Node  `json:"node"`
    PrevNode  *Node  `json:"prevNode,omitempty"`
    EtcdIndex uint64 `json:"etcdIndex"`
    RaftIndex uint64 `json:"raftIndex"`
    RaftTerm  uint64 `json:"raftTerm"`
}

func (*Response) CodecDecodeSelf Uses

func (x *Response) CodecDecodeSelf(d *codec1978.Decoder)

func (*Response) CodecEncodeSelf Uses

func (x *Response) CodecEncodeSelf(e *codec1978.Encoder)

Package etcd imports 21 packages (graph) and is imported by 1785 packages. Updated 2016-07-20. Refresh now. Tools for package owners.