Documentation ¶
Overview ¶
Package etcdlight is a lightweight implementation of the v2 etcd API. This package is here because the module the official Etcd client package is in has a lot of dependencies and we wish to keep sebase depencency light.
Index ¶
- func IsErrorCode(err error, code ...int) bool
- type ErrorResponse
- type KAPI
- func (cl *KAPI) Get(ctx context.Context, key string, recursive bool) (*Response, error)
- func (cl *KAPI) MkDir(ctx context.Context, key string, ttl time.Duration) error
- func (cl *KAPI) RefreshDir(ctx context.Context, key string, ttl time.Duration) error
- func (cl *KAPI) RmDir(ctx context.Context, key string, recursive bool) error
- func (cl *KAPI) Set(ctx context.Context, key string, value string, exclusive bool, ...) error
- func (cl *KAPI) URLForKey(key string) *url.URL
- func (cl *KAPI) Watch(key string, recursive bool, afterIndex uint64) Watcher
- type KV
- type Response
- type Watcher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsErrorCode ¶
IsErrorCode returns true if err is of type *ErrorResponse and the ErrorCode field matches one of the codes given.
Types ¶
type ErrorResponse ¶
type ErrorResponse struct { // StatusCode is set from the HTTP request. StatusCode int // ErrorCode is returned from Etcd. It will be 0 if unset or JSON decoding failed. ErrorCode int // Message is returned from Etcd, but if JSON decoding failed it contains the // HTTP body instead. Message string // Index is the Etcd index returned as part of the error from Etcd. Index uint64 }
Type ErrorResponse is used to report errors from Etcd.
func (*ErrorResponse) Error ¶
func (e *ErrorResponse) Error() string
type KAPI ¶
func NewKAPI ¶
NewKAPI returns a *KAPI with http.DefaultClient and the given URL. It returns errors from url.Parse unwrapped.
func (*KAPI) Get ¶
Get retrieves values. Only the current (latest) values can be retrieved. If recursive is true multiple key-values might be retrieved. Key should start with /. Errors from http.Client.Get and json.DecoderDecode are returned unwrapped. Returns a *ErrorResponse error if the HTTP status code was not 200 or 201.
func (*KAPI) MkDir ¶
MkDir creates a directory at key, possibly with a ttl. Pass 0 as ttl to not expire. Returns errors from http.PostForm unwrapped. Returns a *ErrorResponse error if the HTTP status code was not 200 or 201. Key should start with /.
func (*KAPI) RefreshDir ¶
RefreshDir updates the ttl for a directory. It must already exist. Returns errors from http.PostForm unwrapped. Returns a *ErrorResponse error if the HTTP status code was not 200 or 201. Key should start with /.
func (*KAPI) RmDir ¶
RmDir removes the directory given, possibly recursively. Returns errors from http.Client.Do unwrapped. Returns a *ErrorResponse error if the HTTP status code was not 200 or 201. Key should start with /.
func (*KAPI) Set ¶
func (cl *KAPI) Set(ctx context.Context, key string, value string, exclusive bool, ttl time.Duration) error
Set sets the value at key, possibly with a ttl. Pass 0 as ttl to not expire. If exclusive is true then Set will fail if the key already exists. Key should start with /. Returns errors from http.PostForm unwrapped. Returns a *ErrorResponse error if the HTTP status code was not 200 or 201.
func (*KAPI) Watch ¶
Watch creates a watcher that can be used repeatedly to watch for changes. It will watch for changes after afterIndex. If 0 is used for that argument it will watch for the next future change from the time Next is called. This call doesn't do any network request, it only creates the Watcher object. Call Next to do the actual request. Key should start with /.
type KV ¶
type KV struct { // Key is the full path of the key, starting with /. Key string Value string ModifiedIndex uint64 }
Type KV represents a value in etcd. Only leaf values can be represented.
type Response ¶
type Response struct { // The action that was taken, such as "update". Action string // Max index encountered in either header or parsed ModifiedIndex fields. MaxIndex uint64 // Values matching the given key. Values []KV // PrevValues are currenly only set by Watch. It contains previous // values on updates. PrevValues []KV }
Type Response is a parsed successful response from etcd.
func ReadResponse ¶
ReadResponse parses a response from etcd. If the HTTP response code is not 200 or 201, an *ErrorResponse error is returned. If key is empty string body is decoded but not inspected. If key is not empty string, any non-directory nodes with that prefix is returned in values. This function consumes and closes resp.Body. In addition to *ErrorResponse, it might return errors from reading the body or json.Unmarshal.