>
>
> r, _ = Filter(r, query)
> w = LastErrorWrapper(w)
> _, err = io.Copy(w, r)
> if err != nil and w.LastError != nil { # error writing to output,
> abort.
>
I got halfway through implementing a "LastErrorWrapper" and realized it
looked familiar.. that's because it's described in
https://blog.golang.org/errors-are-values
and as it mentions, bufio.Writer already implements exactly the feature I
need.
Changing my example query function to look like
func runQuery(query string, w io.Writer) {
docs, present := index[query]
if !present {
fmt.Fprintf(w, "No results\n")
}
for _, d := range docs {
bw := bufio.NewWriter(w)
err := dump(d, bw)
if bw.Flush() != nil {
log.Printf("Error dumping document %d while writing: %v", d,
bw.Flush())
return
}
if err != nil {
log.Printf("Error dumping document %d: %v", d, err)
}
}
}
appears to do everything I need. errors from one document are skipped, but
an error inside the writer is fatal.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.