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