From 6240073da1fe37936b4fab1dd8888813fa7d2828 Mon Sep 17 00:00:00 2001 From: Jian Han Date: Sat, 14 Apr 2018 22:41:23 +1000 Subject: [PATCH] [DEV] Zero initialization --- phrasebook/ch04/zero_initialization/main.go | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 phrasebook/ch04/zero_initialization/main.go diff --git a/phrasebook/ch04/zero_initialization/main.go b/phrasebook/ch04/zero_initialization/main.go new file mode 100644 index 0000000..4b6e962 --- /dev/null +++ b/phrasebook/ch04/zero_initialization/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "os" +) + +type Logger struct { + out *os.File +} + +func (l Logger) Log(s string) { + out := l.out + if out == nil { + out = os.Stderr + } + fmt.Fprintf(out, "%s [%d]: %s\n", os.Args[0], + os.Getpid(), s) +} +func (l *Logger) SetOutput(out *os.File) { + l.out = out +} + +func main() { + l := Logger{} + l.Log("test") +}