github.com/go-swagger/go-swagger@v0.31.0/examples/stream-server/biz/count.go (about) 1 package biz 2 3 import ( 4 "encoding/json" 5 "errors" 6 "fmt" 7 "io" 8 "time" 9 10 "github.com/go-swagger/go-swagger/examples/stream-server/models" 11 ) 12 13 // MyCounter is the concrete implementation 14 type MyCounter struct{} 15 16 // Down is the concrete implementation that spits out the JSON bodies 17 func (mc *MyCounter) Down(max int64, w io.Writer) error { 18 if max == 11 { 19 return errors.New("we don't *do* elevensies") 20 } 21 e := json.NewEncoder(w) 22 for ix := int64(0); ix <= max; ix++ { 23 r := max - ix 24 fmt.Printf("Iteration %d\n", r) 25 _ = e.Encode(models.Mark{Remains: &r}) 26 if ix != max { 27 time.Sleep(1 * time.Second) 28 } 29 } 30 return nil 31 }