github.com/l3x/learn-fp-go@v0.0.0-20171228022418-7639825d0b71/2-design-patterns/ch04-solid/06_misc/misc.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "net" 6 ) 7 8 //import "theirpkg" 9 10 //func MyFunction(t *theirpkg.AType) 11 // 12 //func MyOtherFunction(i theirpkg.AnInterface) 13 14 type errorBehavior interface { 15 Retryable() bool 16 } 17 18 19 func IsRetryable(err error) bool { 20 eb, ok := err.(errorBehavior) 21 return ok && eb.Retryable() 22 } 23 24 //type writeFlusher interface { 25 // io.Writer 26 // http.Flusher 27 //} 28 29 type Dividend struct { 30 Val int 31 } 32 func (n Dividend) Divide(divisor int) int { 33 return n.Val/divisor 34 } 35 36 type BytesReadConn struct { 37 net.Conn 38 BytesRead uint64 39 } 40 41 func (brc *BytesReadConn) Read(p []byte) (int, error) { 42 n, err := brc.Conn.Read(p) 43 brc.BytesRead += uint64(n) 44 return n, err 45 } 46 47 func main() { 48 d := Dividend{2} 49 fmt.Printf("%d", d.Divide(0)) 50 }