consul

package
v0.0.0-...-7c4d03a Latest Latest
Warning

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

Go to latest
Published: May 11, 2018 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ErrorKeyNotExist = "Key(%s) does not exist"
	ErrorDirNotExist = "Dir(%s) does not exist"
)
View Source
const FunctionIDsTmpl = "service/go/%s/functionids"

Variables

This section is empty.

Functions

func WatchKey

func WatchKey(consulAddr, key string, handle func(*api.KVPair))

WatchKey 监听某个具体key变化 监听到变化会调用handle,参数为变化key的相关信息

func WatchKeyPrefix

func WatchKeyPrefix(consulAddr, key string, handle func(api.KVPairs))

WatchKeyPrefix 监听某一级目录下所有key变化 监听到变化会调用handle,参数为变化key的相关信息 TODO 需要提供stop?

Types

type Client

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

func NewClient

func NewClient(opts ...ClientOptionFunc) (*Client, error)

func (*Client) Deregister

func (client *Client) Deregister() error

func (*Client) Get

func (client *Client) Get(key string) (string, error)

func (*Client) GetArray

func (client *Client) GetArray(keyPrefix string) ([]string, error)

GetArray

例如
            key                         value
    conn/mongodb/goimhistory/1  172.16.9.221:27017
    conn/mongodb/goimhistory/2  172.16.9.222:27017
keyPrefix=conn/mongodb/goimhistory/
return ["172.16.9.221:27017","172.16.9.222:27017"]

func (*Client) GetChildKeys

func (client *Client) GetChildKeys(keyPrefix string) ([]string, error)

GetChildKeys 获取下一级所有key

func (*Client) GetChildValues

func (client *Client) GetChildValues(keyPrefix string) (api.KVPairs, error)

GetChildValues 获取下一级所有key的值 TODO 如果下一级key也是目录?

func (*Client) GetFloat64

func (client *Client) GetFloat64(key string) (float64, error)

func (*Client) GetHostPort

func (client *Client) GetHostPort(key string) (string, string, error)

func (*Client) GetInt

func (client *Client) GetInt(key string) (int, error)

func (Client) GetInt64

func (client Client) GetInt64(key string) (int64, error)

GetInt64 获取指定key的int64值

func (*Client) GetMap

func (client *Client) GetMap(keyPrefix string) (map[string]string, error)

GetMap 例如

            key                         value
conn/redis/config/master/1/db           0
conn/redis/config/master/1/ip           172.16.9.221
conn/redis/config/master/1/poolsize     1
conn/redis/config/master/1/port         6379
keyPrefix=conn/redis/config/master/1/
return map[db:0 ip:172.16.9.221 poolsize:1 port:6379]

func (Client) GetOrDefault

func (client Client) GetOrDefault(key, defaultValue string) string

GetOrDefault 获取指定key的值,没有就返回缺省值

func (Client) GetOrDefaultInt64

func (client Client) GetOrDefaultInt64(key string, defaultValue int64) int64

GetOrDefaultInt64 获取指定key的int64值,没有就返回缺省值

func (*Client) GetUriAndFunctionIDs

func (client *Client) GetUriAndFunctionIDs(serviceName string) (map[string]string, error)

GetFunctionIDs 获取服务所有权限function id和对应的uri

func (*Client) GetValues

func (client *Client) GetValues(keys []string) (api.KVPairs, error)

func (*Client) KV

func (client *Client) KV() *api.KV

func (*Client) Put

func (client *Client) Put(key, value string) error

type ClientOptionFunc

type ClientOptionFunc func(*Client) error

func SetAddress

func SetAddress(address string) ClientOptionFunc

func SetDatacenter

func SetDatacenter(datacenter string) ClientOptionFunc

func SetHttpBasicAuth

func SetHttpBasicAuth(userName, password string) ClientOptionFunc

func SetScheme

func SetScheme(scheme string) ClientOptionFunc

func SetToken

func SetToken(token string) ClientOptionFunc

func SetWaitTime

func SetWaitTime(waitTime time.Duration) ClientOptionFunc

Jump to

Keyboard shortcuts

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