I need to read sse in my golang app, but instead of real-time, events return buffered. As I can see, this is because of standard golang transport. How can I fix this, without implementing my own transport? This code is inspired by cryptix solution:
resp, _ := http.Get(sseURL)
events := make(chan Event)
wg:= sync.WaitGroup{}
wg.Add(1)
go func() {
event:= Event{}
reader := bufio.NewReader(resp.Body)
for {
line, err := reader.ReadBytes('\n')
if err != nil {
log.Println(os.Stderr, "error during resp.Body read:%s\n", err)
close(events)
}
json.Unmarshal(line,&event)
events<-event
}
wg.Done()
}()
go func(){
for ev:= range events {
log.Println(ev)
}
}()
wg.Wait()
json.Decoder
directly) – JimB