forked from ardanlabs/gotraining
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example1.go
32 lines (25 loc) · 934 Bytes
/
example1.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
// All material is licensed under the Apache License Version 2.0, January 2004
// http://www.apache.org/licenses/LICENSE-2.0
// http://play.golang.org/p/jlTo1IV1RQ
// The io.Reader and io.Writer interfaces allow you to compose all of these different bits together.
// Sample program to show how different functions from the
// standard library use the io.Writer interface.
package main
import (
"bytes"
"fmt"
"os"
)
// main is the entry point for the application.
func main() {
// Create a Buffer value and write a string to the buffer.
// Using the Write method that implements io.Writer.
var b bytes.Buffer
b.Write([]byte("Hello "))
// Use Fprintf to concatenate a string to the Buffer.
// Passing the address of a bytes.Buffer value for io.Writer.
fmt.Fprintf(&b, "World!")
// Write the content of the Buffer to the stdout device.
// Passing the address of a os.File value for io.Writer.
b.WriteTo(os.Stdout)
}