Documentation ¶
Index ¶
- Constants
- func GetChecksParams(serviceName string) map[string]interface{}
- func GetKeyPrefixParams(keyPrefix string) map[string]interface{}
- func GetKeysParams(key string) map[string]interface{}
- func GetParams(kind watchKind) map[string]interface{}
- func RegisterWatchHandler(wh WatchHandler)
- type Config
- type ConsulService
- func (ConsulService) CaddyModule() caddy.ModuleInfo
- func (c *ConsulService) Cleanup() error
- func (c *ConsulService) GetPeers() ([]string, error)
- func (c *ConsulService) Provision(ctx caddy.Context) error
- func (c *ConsulService) RegisterWatch(params map[string]interface{}, fn WatchCallback) error
- func (c *ConsulService) RegisterWatches() error
- func (c *ConsulService) UnmarshalCaddyfile(d *caddyfile.Dispenser) error
- func (c *ConsulService) Validate() error
- type DistributedLock
- type WatchCallback
- type WatchHandler
Constants ¶
const (
// Keyprefix is the key prefix for listening key changes
Keyprefix = "del_cache_key"
)
Variables ¶
This section is empty.
Functions ¶
func GetChecksParams ¶
GetChecksParams gets the params for watching checks event
func GetKeyPrefixParams ¶
GetKeyPrefixParams gets the params for watching prefix event
func GetKeysParams ¶
GetKeysParams gets the params for watching key event
func GetParams ¶
func GetParams(kind watchKind) map[string]interface{}
GetParams returns the common params for all watch events
func RegisterWatchHandler ¶
func RegisterWatchHandler(wh WatchHandler)
RegisterWatchHandler append a pair of watch and handler to the list which will be registered to the consul watch service.
Types ¶
type Config ¶
type Config struct { ServiceName string `json:"service_name,omitempty"` Addr string `json:"addr,omitempty"` HealthURL string `json:"health_url,omitempty"` Token string `json:"token,omitempty"` }
Config is the configuration for the consul
type ConsulService ¶
type ConsulService struct { Client *api.Client KV *api.KV Catalog *api.Catalog Config *Config ServiceIDs []string }
ConsulService handles the client to interact with the consul agent
func (ConsulService) CaddyModule ¶
func (ConsulService) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information
func (*ConsulService) Cleanup ¶
func (c *ConsulService) Cleanup() error
Cleanup releases the holding resources
func (*ConsulService) GetPeers ¶
func (c *ConsulService) GetPeers() ([]string, error)
GetPeers get the peers in the same cluster
func (*ConsulService) Provision ¶
func (c *ConsulService) Provision(ctx caddy.Context) error
Provision init the consul's agent and establish connection
func (*ConsulService) RegisterWatch ¶
func (c *ConsulService) RegisterWatch(params map[string]interface{}, fn WatchCallback) error
RegisterWatch watches the events and attaches the handlers to them
func (*ConsulService) RegisterWatches ¶
func (c *ConsulService) RegisterWatches() error
RegisterWatches registers the specified watches
func (*ConsulService) UnmarshalCaddyfile ¶
func (c *ConsulService) UnmarshalCaddyfile(d *caddyfile.Dispenser) error
UnmarshalCaddyfile deserializes Caddyfile tokens into consulservice's config
distributed consul { service_name addr token health_url }
func (*ConsulService) Validate ¶
func (c *ConsulService) Validate() error
Validate checks the resource is set up correctly
type DistributedLock ¶
type DistributedLock struct { Session *api.Session SessionID string // contains filtered or unexported fields }
DistributedLock holds a session and a lock for mutually exclusive usage.
func NewDistributedLock ¶
func NewDistributedLock(key string) (*DistributedLock, error)
NewDistributedLock new a distributed lock based on consul session
func (*DistributedLock) Lock ¶
func (d *DistributedLock) Lock() (<-chan struct{}, error)
Lock acquires distributed lock
func (*DistributedLock) Unlock ¶
func (d *DistributedLock) Unlock() error
Unlock release the distributed lock
type WatchCallback ¶
type WatchCallback func(data interface{}) error
WatchCallback is a processor for watch event
type WatchHandler ¶
type WatchHandler struct { Pg map[string]interface{} Callback WatchCallback }
WatchHandler holds callback and its params. This will be registered on the consul's watch event.