interface.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2012 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // This file contains the code snippets included in "The Laws of Reflection."
  5. package main
  6. import (
  7. "bufio"
  8. "bytes"
  9. "io"
  10. "os"
  11. )
  12. type MyInt int
  13. var i int
  14. var j MyInt
  15. // STOP OMIT
  16. // Reader is the interface that wraps the basic Read method.
  17. type Reader interface {
  18. Read(p []byte) (n int, err error)
  19. }
  20. // Writer is the interface that wraps the basic Write method.
  21. type Writer interface {
  22. Write(p []byte) (n int, err error)
  23. }
  24. // STOP OMIT
  25. func readers() { // OMIT
  26. var r io.Reader
  27. r = os.Stdin
  28. r = bufio.NewReader(r)
  29. r = new(bytes.Buffer)
  30. // and so on
  31. // STOP OMIT
  32. }
  33. func typeAssertions() (interface{}, error) { // OMIT
  34. var r io.Reader
  35. tty, err := os.OpenFile("/dev/tty", os.O_RDWR, 0)
  36. if err != nil {
  37. return nil, err
  38. }
  39. r = tty
  40. // STOP OMIT
  41. var w io.Writer
  42. w = r.(io.Writer)
  43. // STOP OMIT
  44. var empty interface{}
  45. empty = w
  46. // STOP OMIT
  47. return empty, err
  48. }
  49. func main() {
  50. }