Improve messages for events
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
2971f45d7d
commit
6fe3e8fd8e
|
@ -362,7 +362,7 @@ func (c *Client) Events() (chan sse.Message, error) {
|
|||
for {
|
||||
res, err := c.microsubGetRequest("events", nil)
|
||||
if err != nil {
|
||||
log.Printf("could not request events: %s", err)
|
||||
log.Printf("could not request events: %+v", err)
|
||||
errorCounter++
|
||||
if errorCounter > 5 {
|
||||
break
|
||||
|
@ -372,7 +372,7 @@ func (c *Client) Events() (chan sse.Message, error) {
|
|||
|
||||
err = sse.Reader(res.Body, ch)
|
||||
if err != nil {
|
||||
log.Printf("could not create reader: %s", err)
|
||||
log.Printf("could not create reader: %+v", err)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,11 +117,6 @@ func WriteMessages(w http.ResponseWriter, messageChan chan Message) error {
|
|||
w.Header().Set("Connection", "keep-alive")
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
|
||||
_, err := fmt.Fprintf(w, "event: started\r\n")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var welcomeMsg welcomeMessage
|
||||
welcomeMsg.Version = "1.0.0"
|
||||
encoded, err := json.Marshal(&welcomeMsg)
|
||||
|
@ -129,6 +124,11 @@ func WriteMessages(w http.ResponseWriter, messageChan chan Message) error {
|
|||
return errors.Wrap(err, "could not encode welcome message")
|
||||
}
|
||||
|
||||
_, err = fmt.Fprintf(w, "event: started\r\n")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = fmt.Fprintf(w, "data: %s", encoded)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -181,7 +181,7 @@ func Reader(body io.ReadCloser, ch MessageChan) error {
|
|||
}
|
||||
}
|
||||
if err := r.Err(); err != nil {
|
||||
return errors.Wrap(err, "could not scan lines from sse events: %+v")
|
||||
return errors.Wrap(err, "could not scan lines from sse events")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user