Help us shape the future of Go! Take the 2026 Go Developer Survey

distributed

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2023 License: MIT Imports: 12 Imported by: 1

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 added in v0.4.3

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

GetChecksParams gets the params for watching checks event

func GetKeyPrefixParams added in v0.4.3

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

GetKeyPrefixParams gets the params for watching prefix event

func GetKeysParams added in v0.4.3

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

GetKeysParams gets the params for watching key event

func GetParams added in v0.4.3

func GetParams(kind watchKind) map[string]interface{}

GetParams returns the common params for all watch events

func RegisterWatchHandler added in v0.4.3

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 added in v0.4.3

func (c *ConsulService) RegisterWatch(params map[string]interface{}, fn WatchCallback) error

RegisterWatch watches the events and attaches the handlers to them

func (*ConsulService) RegisterWatches added in v0.4.3

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 added in v0.4.3

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 added in v0.4.3

func NewDistributedLock(key string) (*DistributedLock, error)

NewDistributedLock new a distributed lock based on consul session

func (*DistributedLock) Destroy added in v0.4.3

func (d *DistributedLock) Destroy()

Destroy release the session

func (*DistributedLock) Lock added in v0.4.3

func (d *DistributedLock) Lock() (<-chan struct{}, error)

Lock acquires distributed lock

func (*DistributedLock) Unlock added in v0.4.3

func (d *DistributedLock) Unlock() error

Unlock release the distributed lock

type WatchCallback added in v0.4.3

type WatchCallback func(data interface{}) error

WatchCallback is a processor for watch event

type WatchHandler added in v0.4.3

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