-
Notifications
You must be signed in to change notification settings - Fork 1
/
4.go
37 lines (33 loc) · 834 Bytes
/
4.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// popular example: http.HandlerFunc that implement the Handler interface.
//
// link: https://golang.org/src/net/http/server.go?s=57220:57267#L1928
package main
import (
"fmt"
"io"
"strings"
)
// WriterFunc is a typed func that implements the io.Writer interface.
type WriterFunc func([]byte) (int, error)
func (fn WriterFunc) Write(p []byte) (int, error) { return fn(p) }
func main() {
for _, writer := range []WriterFunc{
// writer 1
func(p []byte) (int, error) {
fmt.Printf("writer-1 %s", string(p))
return len(p), nil
},
// writer 2
func(p []byte) (int, error) {
fmt.Printf("writer-2 %s", string(p))
return len(p), nil
},
// writer 3
func(p []byte) (int, error) {
fmt.Printf("writer-3 %s", string(p))
return len(p), nil
},
} {
io.Copy(writer, strings.NewReader("boring...\n"))
}
}