GoodStream checks whether there's errors in `stream`
(stream chan interface{})
| 30 | |
| 31 | // GoodStream checks whether there's errors in `stream` |
| 32 | func GoodStream(stream chan interface{}) (bool, string) { |
| 33 | lastResp := list.New() |
| 34 | keepSize := 10 |
| 35 | |
| 36 | for rsp := range stream { |
| 37 | switch rsp.(type) { |
| 38 | case error: |
| 39 | var ss []string |
| 40 | for e := lastResp.Front(); e != nil; e = e.Next() { |
| 41 | if s, ok := e.Value.(string); ok { |
| 42 | ss = append(ss, s) |
| 43 | } |
| 44 | } |
| 45 | return false, fmt.Sprintf("%v: %s", rsp, strings.Join(ss, "\n")) |
| 46 | } |
| 47 | lastResp.PushBack(rsp) |
| 48 | if lastResp.Len() > keepSize { |
| 49 | e := lastResp.Front() |
| 50 | lastResp.Remove(e) |
| 51 | } |
| 52 | } |
| 53 | return true, "" |
| 54 | } |
no outgoing calls