Fix double body read, improve logging
This commit is contained in:
@@ -54,7 +54,7 @@ func (gc *garminClient) sendMessage(imei, sender, msg string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("sending message to garmin: %s", buf.String())
|
log.Printf("[->garmin] %s", buf.String())
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "https://ipcinbound.inreachapp.com/IPC/IPCInboundApi/api/Messaging/Message", buf)
|
req, err := http.NewRequest("POST", "https://ipcinbound.inreachapp.com/IPC/IPCInboundApi/api/Messaging/Message", buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -77,11 +77,13 @@ func (gc *garminClient) sendMessage(imei, sender, msg string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
grResp := garminMessageResponse{}
|
grResp := garminMessageResponse{}
|
||||||
err = json.NewDecoder(resp.Body).Decode(&grResp)
|
err = json.Unmarshal(body, &grResp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("[<-garmin] %s", string(body))
|
||||||
|
|
||||||
if grResp.Count != 1 {
|
if grResp.Count != 1 {
|
||||||
return fmt.Errorf("expected 1 message, got %d", grResp.Count)
|
return fmt.Errorf("expected 1 message, got %d", grResp.Count)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -48,6 +49,8 @@ func (pd *pdClient) sendAlert(msg string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("[->pagerduty] %s", buf.String())
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "https://events.pagerduty.com/v2/enqueue", buf)
|
req, err := http.NewRequest("POST", "https://events.pagerduty.com/v2/enqueue", buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -67,5 +70,7 @@ func (pd *pdClient) sendAlert(msg string) error {
|
|||||||
return fmt.Errorf("%s", string(body))
|
return fmt.Errorf("%s", string(body))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("[<-pagerduty] %s", string(body))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user