mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-25 14:26:04 +03:00
[DEV] Zero initialization
This commit is contained in:
parent
5fe2f0aa7f
commit
6240073da1
27
phrasebook/ch04/zero_initialization/main.go
Normal file
27
phrasebook/ch04/zero_initialization/main.go
Normal file
@ -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")
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user