@@ -20,7 +20,6 @@ import (
2020 "encoding/binary"
2121 "errors"
2222 "fmt"
23- "log"
2423 "net"
2524 "plugin"
2625 "sort"
@@ -30,6 +29,7 @@ import (
3029
3130 "github.com/buraksezer/olric/config"
3231 "github.com/buraksezer/olric/internal/flog"
32+ "github.com/buraksezer/olric/pkg/service_discovery"
3333 "github.com/hashicorp/memberlist"
3434 "github.com/vmihailenco/msgpack"
3535)
@@ -39,30 +39,6 @@ const eventChanCapacity = 256
3939// ErrHostNotFound indicates that the requested host could not be found in the member list.
4040var ErrHostNotFound = errors .New ("host not found" )
4141
42- // ServiceDiscovery is an interface that defines a unified API for service discovery plugins.
43- type ServiceDiscovery interface {
44- // Initialize initializes the plugin: registers some internal data structures, clients etc.
45- Initialize () error
46-
47- // SetConfig registers plugin configuration
48- SetConfig (c map [string ]interface {}) error
49-
50- // SetLogger sets an appropriate
51- SetLogger (l * log.Logger )
52-
53- // Register registers this node to a service discovery directory.
54- Register () error
55-
56- // Deregister removes this node from a service discovery directory.
57- Deregister () error
58-
59- // DiscoverPeers returns a list of known Olric nodes.
60- DiscoverPeers () ([]string , error )
61-
62- // Close stops underlying goroutines, if there is any. It should be a blocking call.
63- Close () error
64- }
65-
6642// ClusterEvent is a single event related to node activity in the memberlist.
6743// The Node member of this struct must not be directly modified.
6844type ClusterEvent struct {
@@ -95,7 +71,7 @@ type Discovery struct {
9571 deadMemberEvents chan * ClusterEvent
9672
9773 eventSubscribers []chan * ClusterEvent
98- serviceDiscovery ServiceDiscovery
74+ serviceDiscovery service_discovery. ServiceDiscovery
9975
10076 // Flow control
10177 wg sync.WaitGroup
@@ -154,10 +130,10 @@ func New(log *flog.Logger, c *config.Config) (*Discovery, error) {
154130}
155131
156132func (d * Discovery ) loadServiceDiscoveryPlugin () error {
157- var sd ServiceDiscovery
133+ var sd service_discovery. ServiceDiscovery
158134
159135 if val , ok := d .config .ServiceDiscovery ["plugin" ]; ok {
160- if sd , ok = val .(ServiceDiscovery ); ! ok {
136+ if sd , ok = val .(service_discovery. ServiceDiscovery ); ! ok {
161137 return fmt .Errorf ("plugin type %T is not a ServiceDiscovery interface" , val )
162138 }
163139 } else {
@@ -175,7 +151,7 @@ func (d *Discovery) loadServiceDiscoveryPlugin() error {
175151 return fmt .Errorf ("failed to lookup serviceDiscovery symbol: %w" , err )
176152 }
177153
178- if sd , ok = symDiscovery .(ServiceDiscovery ); ! ok {
154+ if sd , ok = symDiscovery .(service_discovery. ServiceDiscovery ); ! ok {
179155 return fmt .Errorf ("unable to assert type to serviceDiscovery" )
180156 }
181157 }
0 commit comments