diff --git a/marshal.go b/marshal.go index 8c9fbfa..a500661 100644 --- a/marshal.go +++ b/marshal.go @@ -85,13 +85,21 @@ func (i *Instance) UnmarshalJSON(b []byte) error { if err = json.Unmarshal(b, &ii); err == nil { marshalLog.Debug("Instance.UnmarshalJSON ii:%+v\n", ii) *i = Instance(ii) - i.Port, _ = strconv.Atoi(ii.PortJ.Number) - i.SecurePort, _ = strconv.Atoi(ii.SecurePortJ.Number) + i.Port = parsePort(ii.PortJ.Number) + i.SecurePort = parsePort(ii.SecurePortJ.Number) return nil } return err } +func parsePort(s string) int { + n, err := strconv.Atoi(s) + if err != nil { + log.Warning("Invalid port error: %s", err.Error()) + } + return n +} + // UnmarshalJSON is a custom JSON unmarshaler for InstanceMetadata to handle squirreling away // the raw JSON for later parsing. func (i *InstanceMetadata) UnmarshalJSON(b []byte) error { diff --git a/net.go b/net.go index 517a490..4d67edd 100644 --- a/net.go +++ b/net.go @@ -235,7 +235,7 @@ func (e EurekaConnection) AddMetadataString(ins *Instance, key, value string) er log.Debug("Updating instance metadata url=%s metadata=%s", reqURL, params) body, rcode, err := putKV(reqURL, params) if err != nil { - log.Error("Could not complete update, error: ", err.Error()) + log.Error("Could not complete update, error: %s", err.Error()) return err } if rcode < 200 || rcode >= 300 { diff --git a/tests/marshal_test.go b/tests/marshal_test.go index 2b152fb..695b189 100644 --- a/tests/marshal_test.go +++ b/tests/marshal_test.go @@ -19,16 +19,16 @@ func TestJsonMarshal(t *testing.T) { var v fargo.GetAppsResponseJson err = json.Unmarshal(blob, &v) - // Handy dump for debugging funky JSON - fmt.Printf("v:\n%+v\n", v.Response.Applications) - for _, app := range v.Response.Applications { - fmt.Printf(" %+v\n", *app) - for _, ins := range app.Instances { - fmt.Printf(" %+v\n", *ins) + if err != nil { + // Handy dump for debugging funky JSON + fmt.Printf("v:\n%+v\n", v.Response.Applications) + for _, app := range v.Response.Applications { + fmt.Printf(" %+v\n", *app) + for _, ins := range app.Instances { + fmt.Printf(" %+v\n", *ins) + } } - } - if err != nil { // Print a little more details when there are unmarshalling problems switch ute := err.(type) { case *json.UnmarshalTypeError: