forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adaptor.go
55 lines (46 loc) · 852 Bytes
/
adaptor.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
53
54
55
package gobot
import "fmt"
type Adaptor struct {
Name string
Port string
Connected bool
Params map[string]interface{}
Type string
}
type AdaptorInterface interface {
Finalize() bool
Connect() bool
port() string
name() string
setName(string)
params() map[string]interface{}
}
func (a *Adaptor) port() string {
return a.Port
}
func (a *Adaptor) name() string {
return a.Name
}
func (a *Adaptor) setName(s string) {
a.Name = s
}
func (a *Adaptor) params() map[string]interface{} {
return a.Params
}
func (a *Adaptor) ToJSON() *JSONConnection {
return &JSONConnection{
Name: a.Name,
Port: a.Port,
Adaptor: a.Type,
}
}
func NewAdaptor(name, port, t string) *Adaptor {
if name == "" {
name = fmt.Sprintf("%X", Rand(int(^uint(0)>>1)))
}
return &Adaptor{
Type: t,
Name: name,
Port: port,
}
}