judge

package
v0.0.0-...-693abe4 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2019 License: MIT Imports: 7 Imported by: 0

README

judge

a package for golang to manage cluster, including register and election

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LockTTL          = time.Second * 10
	RegisterTTL      = time.Second * 10
	RegisterInterval = time.Second * 3
)

keys' ttl

Functions

func Store

func Store(endpoints []string) (etcd.KeysAPI, error)

Store return a KeysAPI of etcd

Types

type Candidate

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

Candidate represent a member in Cluster

func Register

func Register(ctx context.Context, config *Config) (*Candidate, error)

Register create a new Candidate on specific service, and return it. icandidate quit the service when context was canceled

func (*Candidate) Leader

func (c *Candidate) Leader() (string, error)

Leader return the leader address

func (*Candidate) Members

func (c *Candidate) Members() ([]string, error)

Members return all the members

func (*Candidate) WatchLeader

func (c *Candidate) WatchLeader(ctx context.Context) (<-chan string, error)

WatchLeader return a channel, which output leader value when leader changed

func (*Candidate) WatchMembers

func (c *Candidate) WatchMembers(ctx context.Context) (<-chan []string, error)

WatchMembers return a channel, which output the member list when updated

type Config

type Config struct {
	Endpoints []string
	Prefix    string
	Advertise string
	Election  bool
}

Config for create cluster

type Lock

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

Lock represent a distribute lock

func NewLock

func NewLock(kv etcd.KeysAPI, key, value string) *Lock

NewLock returns a handle to a lock struct which can be used to provide mutual exclusion on a key

func (*Lock) Lock

func (l *Lock) Lock(ctx context.Context) (<-chan struct{}, error)

Lock attempts to acquire the lock and blocks while doing so. It returns a channel that is closed if our lock is lost or if an error occurs

func (*Lock) Unlock

func (l *Lock) Unlock() error

Unlock the "key". Calling unlock while not holding the lock will throw an error

Jump to

Keyboard shortcuts

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