Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(307)

Delta Between Two Patch Sets: 2014/go4java/writecounter.go

Issue 111050043: code review 111050043: go.talks: add "Go for Javaneros" (Closed)
Left Patch Set: Created 9 years, 8 months ago
Right Patch Set: diff -r f10c43fe60f9 https://code.google.com/p/go.talks Created 9 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« 2014/go4java.slide ('K') | « 2014/go4java/runner/runner.go ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 package main
2
3 import (
4 "bytes"
5 "fmt"
6 "io"
7 "os"
8 )
9
10 var (
11 _ = bytes.Buffer{}
12 _ = os.Stdout
13 )
14
15 // WriteCounter counts how many times `Write` is called
u 2014/07/16 11:51:47 "counts how many times `Write` is called" should b
campoy 2014/07/16 17:41:30 Done.
16 type WriteCounter struct {
17 io.ReadWriter
18 count int
19 }
20
21 func (w *WriteCounter) Write(b []byte) (int, error) {
22 w.count += len(b)
23 return w.ReadWriter.Write(b)
24 }
25
26 // MAIN OMIT
27 func main() {
28 buf := &bytes.Buffer{}
29 w := &WriteCounter{ReadWriter: buf}
30
31 fmt.Fprintf(w, "Hello, gophers!\n")
32 fmt.Printf("Printed %v bytes", w.count)
33 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b