func (this *HttpResponse) ProcessResults() (int, error) { for val := range this.results { if this.count == 0 { _, err := this.openArray("resultset") if err != nil { return 0, err } } else { _, err := this.continueResponse() if err != nil { return 0, err } } valSanitized := misc.SanitizeUnrepresentableJSON(val) _, err := this.printObj(valSanitized) if err != nil { return 0, err } this.count++ // flush response so client receives rows as soon as possible if f, ok := this.w.(http.Flusher); ok { f.Flush() } } // close resultset if this.count == 0 && this.err == nil { _, err := this.openArray("resultset") if err != nil { return 0, err } _, err = this.closeArray() if err != nil { return 0, err } } else if this.count != 0 { _, err := this.continueResponseLast() if err != nil { return 0, err } _, err = this.closeArray() if err != nil { return 0, err } } return 0, nil }
func (this *MockResponse) SendResult(val interface{}) { // sanitize the value the same way the HTTP endpoint does sanitizedValue := misc.SanitizeUnrepresentableJSON(val) this.results = append(this.results, sanitizedValue) }