1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-26 13:48:49 +08:00
hybridgroup.gobot/connection.go

53 lines
1.0 KiB
Go
Raw Normal View History

2014-04-30 08:10:44 -07:00
package gobot
2014-04-29 13:20:32 -07:00
import (
"errors"
"log"
)
2014-06-10 15:16:11 -07:00
type JSONConnection struct {
2014-05-15 11:50:45 -07:00
Name string `json:"name"`
Port string `json:"port"`
Adaptor string `json:"adaptor"`
}
2014-06-23 20:33:59 -07:00
type connections struct {
connections []AdaptorInterface
}
func (c *connections) Len() int {
return len(c.connections)
2014-04-30 08:10:44 -07:00
}
2014-06-23 20:33:59 -07:00
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)
}
}
2014-04-29 13:20:32 -07:00
// Start() starts all the connections.
func (c connections) Start() error {
var err error
log.Println("Starting connections...")
2014-06-23 20:33:59 -07:00
for _, connection := range c.connections {
log.Println("Starting connection " + connection.name() + "...")
2014-04-29 13:20:32 -07:00
if connection.Connect() == false {
err = errors.New("Could not start connection")
break
}
}
return err
}
// Filanize() finalizes all the connections.
func (c connections) Finalize() {
2014-06-23 20:33:59 -07:00
for _, connection := range c.connections {
2014-04-29 13:20:32 -07:00
connection.Finalize()
}
}