Created
June 26, 2020 04:48
-
-
Save heiwa4126/c9b801e011821da6f864a664e64a8fb6 to your computer and use it in GitHub Desktop.
io.Writeインタフェースを持つ構造体Hogeの例
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
type Hoge struct { | |
label string | |
cnt int | |
} | |
func (h *Hoge) Write(b []byte) (n int, err error) { | |
h.cnt++ | |
fmt.Printf("(%s:%d) len=%d bytes\n", h.label, h.cnt, len(b)) | |
return len(b), nil | |
} | |
func main() { | |
h := &Hoge{"hoge1", 0} | |
fmt.Printf("%#v\n", h) | |
fmt.Fprintf(h, "Hello, world") | |
fmt.Fprintf(h, "Hello, world once again") | |
fmt.Printf("%#v\n", h) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
実行結果 - The Go Playground