Fix addPeer to make interface= optional

This commit is contained in:
Neil Alexander 2018-09-25 17:13:35 +01:00
parent 1796000b05
commit b368421dbd
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944

View File

@ -113,18 +113,22 @@ func (a *admin) init(c *Core, listenaddr string) {
return admin_info{"sessions": sessions}, nil return admin_info{"sessions": sessions}, nil
}) })
a.addHandler("addPeer", []string{"uri", "[interface]"}, func(in admin_info) (admin_info, error) { a.addHandler("addPeer", []string{"uri", "[interface]"}, func(in admin_info) (admin_info, error) {
if a.addPeer(in["uri"].(string), in["interface"].(string)) == nil { // Set sane defaults
intf := ""
// Has interface been specified?
if itf, ok := in["interface"]; ok {
intf = itf.(string)
}
if a.addPeer(in["uri"].(string), intf) == nil {
return admin_info{ return admin_info{
"added": []string{ "added": []string{
in["uri"].(string), in["uri"].(string),
in["interface"].(string),
}, },
}, nil }, nil
} else { } else {
return admin_info{ return admin_info{
"not_added": []string{ "not_added": []string{
in["uri"].(string), in["uri"].(string),
in["interface"].(string),
}, },
}, errors.New("Failed to add peer") }, errors.New("Failed to add peer")
} }