-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathconnection.go
52 lines (44 loc) · 1.02 KB
/
connection.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 gobot
import (
"errors"
"log"
)
type JSONConnection struct {
Name string `json:"name"`
Port string `json:"port"`
Adaptor string `json:"adaptor"`
}
type connections struct {
connections []AdaptorInterface
}
func (c *connections) Len() int {
return len(c.connections)
}
func (c *connections) Add(a AdaptorInterface) AdaptorInterface {
c.connections = append(c.connections, a)
return a
}
func (c *connections) Each(f func(AdaptorInterface)) {
for _, connection := range c.connections {
f(connection)
}
}
// Start() starts all the connections.
func (c connections) Start() error {
var err error
log.Println("Starting connections...")
for _, connection := range c.connections {
log.Println("Starting connection " + connection.name() + "...")
if connection.Connect() == false {
err = errors.New("Could not start connection")
break
}
}
return err
}
// Filanize() finalizes all the connections.
func (c connections) Finalize() {
for _, connection := range c.connections {
connection.Finalize()
}
}