concept writer in category go
appears as: Writer

This is an excerpt from Manning's book Go in Action.
Listing 5.34. listing34.go
01 // Sample program to show how to write a simple version of curl using 02 // the io.Reader and io.Writer interface support. 03 package main 04 05 import ( 06 "fmt" 07 "io" 08 "net/http" 09 "os" 10 ) 11 12 // init is called before main. 13 func init() { 14 if len(os.Args) != 2 { 15 fmt.Println("Usage: ./example2 <url>") 16 os.Exit(-1) 17 } 18 } 19 20 // main is the entry point for the application. 21 func main() { 22 // Get a response from the web server. 23 r, err := http.Get(os.Args[1]) 24 if err != nil { 25 fmt.Println(err) 26 return 27 } 28 29 // Copies from the Body to Stdout. 30 io.Copy(os.Stdout, r.Body) 31 if err := r.Body.Close(); err != nil { 32 fmt.Println(err) 33 } 34 }
Listing 8.14. golang.org/src/log/log.go
// New creates a new Logger. The out variable sets the // destination to which log data will be written. // The prefix appears at the beginning of each generated log line. // The flag argument defines the logging properties. func New(out io.Writer, prefix string, flag int) *Logger { return &Logger{out: out, prefix: prefix, flag: flag} }