Skip to content

Commit 86d88c0

Browse files
committed
types: add connector manager
1 parent d0cbc83 commit 86d88c0

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

pkg/types/connectivity.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
package types
22

33
import (
4+
"context"
5+
"fmt"
46
"sync"
57
)
68

9+
type Connector interface {
10+
Connect(ctx context.Context) error
11+
}
12+
713
func allTrue(bools []bool) bool {
814
for _, b := range bools {
915
if !b {
@@ -125,3 +131,27 @@ func (c *Connectivity) Bind(stream Stream) {
125131
stream.OnAuth(c.setAuthed)
126132
c.stream = stream
127133
}
134+
135+
type ConnectorManager struct {
136+
connectors map[Connector]Connector
137+
}
138+
139+
func NewConnectorManager() *ConnectorManager {
140+
return &ConnectorManager{
141+
connectors: make(map[Connector]Connector),
142+
}
143+
}
144+
145+
func (cm *ConnectorManager) Add(connector Connector) {
146+
cm.connectors[connector] = connector
147+
}
148+
149+
func (cm *ConnectorManager) Connect(ctx context.Context) error {
150+
for _, connector := range cm.connectors {
151+
if err := connector.Connect(ctx); err != nil {
152+
return fmt.Errorf("connector %T connect error: %w", connector, err)
153+
}
154+
}
155+
156+
return nil
157+
}

0 commit comments

Comments
 (0)