Skip to content

Commit 8650b65

Browse files
committed
Move ServiceDiscovery plugin interface out of internal/ path #38
1 parent 141108f commit 8650b65

File tree

2 files changed

+48
-29
lines changed

2 files changed

+48
-29
lines changed

internal/discovery/discovery.go

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
4040
var 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.
6844
type 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

156132
func (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
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2018-2020 Burak Sezer
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/*Package service_discovery provides ServiceDiscovery interface for plugins*/
16+
package service_discovery
17+
18+
import "log"
19+
20+
// ServiceDiscovery is an interface that defines a unified API for service discovery plugins.
21+
type ServiceDiscovery interface {
22+
// Initialize initializes the plugin: registers some internal data structures, clients etc.
23+
Initialize() error
24+
25+
// SetConfig registers plugin configuration
26+
SetConfig(c map[string]interface{}) error
27+
28+
// SetLogger sets an appropriate
29+
SetLogger(l *log.Logger)
30+
31+
// Register registers this node to a service discovery directory.
32+
Register() error
33+
34+
// Deregister removes this node from a service discovery directory.
35+
Deregister() error
36+
37+
// DiscoverPeers returns a list of known Olric nodes.
38+
DiscoverPeers() ([]string, error)
39+
40+
// Close stops underlying goroutines, if there is any. It should be a blocking call.
41+
Close() error
42+
}
43+

0 commit comments

Comments
 (0)