gotype: clean handling of stdin, added tests

- removed uses of global variables
- minor cleanups

R=r
CC=golang-dev
https://golang.org/cl/4277044
5 files changed