distributed

package
v0.4.4-0...-300e47e Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// Keyprefix is the key prefix for listening key changes
	Keyprefix = "del_cache_key"
)

Variables

This section is empty.

Functions

func GetChecksParams

func GetChecksParams(serviceName string) map[string]interface{}

GetChecksParams gets the params for watching checks event

func GetKeyPrefixParams

func GetKeyPrefixParams(keyPrefix string) map[string]interface{}

GetKeyPrefixParams gets the params for watching prefix event

func GetKeysParams

func GetKeysParams(key string) map[string]interface{}

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) Destroy

func (d *DistributedLock) Destroy()

Destroy release the 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.

Jump to

Keyboard shortcuts

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