-
Notifications
You must be signed in to change notification settings - Fork 3
/
interface.go
52 lines (44 loc) · 1.34 KB
/
interface.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package targetsync
import (
"context"
"fmt"
"time"
)
// Target represents a single IP+Port pair
type Target struct {
IP string
Port int
}
// Key returns a unique key identifying this specific target
func (t *Target) Key() string {
return fmt.Sprintf("%s:%d", t.IP, t.Port)
}
// TargetSource is an interface for getting targets for a given config
// TODO: plugin etc.
type TargetSource interface {
Subscribe(context.Context) (chan []*Target, error)
}
// TargetDestination is a place to apply targets to (e.g. TargetGroup)
type TargetDestination interface {
// GetTargets returns the current set of targets at the destination
GetTargets(context.Context) ([]*Target, error)
// AddTargets simply adds the targets described
AddTargets(context.Context, []*Target) error
// RemoveTargets simply removes the targets described
RemoveTargets(context.Context, []*Target) error
}
// LockOptions holds the options for locking/leader-election
type LockOptions struct {
Key string `yaml:"key"`
TTL time.Duration `yaml:"ttl"`
}
// Locker is an interface for locking/leader-election
type Locker interface {
// Lock will acquire the lock defined in `LockOptions` and return a channel
// which will respond with whether we are the leader
Lock(context.Context, *LockOptions) (<-chan bool, error)
}
type TargetSourceLocker interface {
Locker
TargetSource
}