Example:
In package io
the type ByteReader
defines an interface that wraps the method ReadByte() (c byte, err error)
.
What is the easiest way to find out which types in the standard library (i.e. listed here in golang.org/pkg) satisfy this interface?
Is this just a matter of experience or is there any other help?
When you define a new interface, you are defining a new reference data type. You can use interface names anywhere you can use any other data type name. If you define a reference variable whose type is an interface, any object you assign to it must be an instance of a class that implements the interface.
Mostly by experience. Anyway, for example:
jnml@fsc-r630:~/go/src/pkg$ egrep -nr '^func (.*) ReadByte\(' *
bufio/bufio.go:165:func (b *Reader) ReadByte() (c byte, err error) {
bytes/reader.go:59:func (r *Reader) ReadByte() (b byte, err error) {
bytes/buffer.go:289:func (b *Buffer) ReadByte() (c byte, err error) {
encoding/xml/xml_test.go:234:func (d *downCaser) ReadByte() (c byte, err error) {
strings/reader.go:58:func (r *Reader) ReadByte() (b byte, err error) {
jnml@fsc-r630:~/go/src/pkg$
And also the golang.org site has a case sensitive search capability.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With