Add support for additional parameters

This commit is contained in:
Adrian Zankich 2013-12-06 14:44:48 -08:00
parent 0f775fe6ae
commit 6b7554a900
2 changed files with 7 additions and 2 deletions

View File

@ -4,7 +4,7 @@ type Adaptor struct {
Name string Name string
Port string Port string
Connected bool Connected bool
Params map[string]string Params map[string]interface{}
} }
func (Adaptor) NewAdaptor(a Adaptor) Adaptor { func (Adaptor) NewAdaptor(a Adaptor) Adaptor {

View File

@ -10,13 +10,18 @@ type Connection struct {
Adaptor interface{} Adaptor interface{}
Port string Port string
Robot *Robot `json:"-"` Robot *Robot `json:"-"`
Params map[string]string Params map[string]interface{}
} }
func NewConnection(a interface{}, r *Robot) *Connection { func NewConnection(a interface{}, r *Robot) *Connection {
c := new(Connection) c := new(Connection)
c.Name = reflect.ValueOf(a).Elem().FieldByName("Name").String() c.Name = reflect.ValueOf(a).Elem().FieldByName("Name").String()
c.Port = reflect.ValueOf(a).Elem().FieldByName("Port").String() c.Port = reflect.ValueOf(a).Elem().FieldByName("Port").String()
c.Params = make(map[string]interface{})
keys := reflect.ValueOf(a).Elem().FieldByName("Params").MapKeys()
for k := range keys {
c.Params[keys[k].String()] = reflect.ValueOf(a).Elem().FieldByName("Params").MapIndex(keys[k])
}
c.Robot = r c.Robot = r
c.Adaptor = a c.Adaptor = a
return c return c