Change ipAddress to IPAddresses and add error message on unknown ip addr type

This commit is contained in:
Praneeth Bodduluri 2015-09-18 22:29:25 +05:30 committed by Pablo Carranza Vélez
parent bc0afb0032
commit 391a141843
2 changed files with 4 additions and 3 deletions

View File

@ -143,6 +143,7 @@ func ipAddress() (ipAddresses []string, err error) {
case *net.IPAddr:
ip = v.IP
default:
log.Printf("Warning: Unrecognised type %T\n", v)
continue
}
if ip == nil {
@ -151,7 +152,7 @@ func ipAddress() (ipAddresses []string, err error) {
if ip = ip.To4(); ip == nil {
continue // This isnt an IPv4 Addresss
}
ipAddresses = append(ipAddresses, ip.String())
ipAddresses = append(IPAddresses, ip.String())
}
}
return
@ -168,7 +169,7 @@ func IPAddressHandler(writer http.ResponseWriter, request *http.Request) {
sendError("Invalid request")
} else {
payload := make(map[string][]string)
payload["IPAddress"] = ipAddr
payload["IPAddresses"] = ipAddr
sendResponse(payload, "", http.StatusOK)
}
}

View File

@ -58,7 +58,7 @@ knex.init.then ->
callback = (error, response, body ) ->
if !error && response.statusCode == 200
device.updateState(
ip_address: body.Data.IPAddress.join(' ')
ip_address: body.Data.IPAddresses.join(' ')
)
request.get({ url: "#{config.gosuperAddress}/v1/ipaddr", json: true }, callback )