Go documentation - how to determine what implements an interface?

223 views
Skip to first unread message

White Hexagon

unread,
May 15, 2019, 10:56:17 AM5/15/19
to golang-nuts
I have another strange interface with the Go AWS SDK.  The PutObject is expecting the data as an: io.ReadSeeker

I imagine there is something implementing this in Go.  But my question is how would a new user find this information?  The go documentation for the API just tells me there is a Reader and a Seeker but not what might be implementing the interface.  I imagine this is difficult to generate since there is no explicit keyword 'implements' but I also imagine it is documented somewhere?

Cheers
Peter
go1.12.1

Tamás Gulácsi

unread,
May 15, 2019, 12:00:52 PM5/15/19
to golang-nuts
Just check the definition:https://golang.org/pkg/io/#ReadSeeker
Anything that implements a proper Read and Seek method, also implements the io.ReadSeeker interface.

Sam Mortimer

unread,
May 15, 2019, 3:33:48 PM5/15/19
to golang-nuts
There is guru (https://docs.google.com/document/d/1_Y9xCEMj5S-7rv2ooHpZNH15JgRT5iM742gJkw5LtmQ/edit) but it's intended for editors not humans.   I suppose that means perhaps you could use one of the editors that uses guru ?

Regards,
-Sam.

src/io/io.go:#5381 is where io.ReadSeeker is defined:

$ guru implements src/io/io.go:#5381 |grep gomaster/src |grep -v _test.go |sort
gomaster/src/bytes/reader.go:18.6-18.11: is implemented by pointer type *bytes.Reader
gomaster/src/cmd/compile/internal/gc/iimport.go:241.6-241.17: is implemented by pointer type *cmd/compile/internal/gc.importReader
gomaster/src/cmd/go/internal/lockedfile/lockedfile.go:24.6-24.9: is implemented by struct type cmd/go/internal/lockedfile.File
gomaster/src/cmd/go/internal/lockedfile/lockedfile.go:31.6-31.11: is implemented by struct type cmd/go/internal/lockedfile.osFile
gomaster/src/cmd/go/internal/modfetch/codehost/vcs.go:450.6-450.17: is implemented by struct type cmd/go/internal/modfetch/codehost.deleteCloser
gomaster/src/debug/elf/reader.go:13.6-13.16: is implemented by struct type debug/elf.errorReader
gomaster/src/debug/elf/reader.go:37.6-37.25: is implemented by pointer type *debug/elf.readSeekerFromReader
gomaster/src/go/internal/gcimporter/iimport.go:21.6-21.14: is implemented by struct type go/internal/gcimporter.intReader
gomaster/src/internal/poll/fd_unix.go:18.6-18.7: is implemented by pointer type *internal/poll.FD
gomaster/src/io/io.go:115.6-115.11: implements Seeker
gomaster/src/io/io.go:145.6-145.15: interface type ReadSeeker
gomaster/src/io/io.go:157.6-157.20: is implemented by interface type ReadWriteSeeker
gomaster/src/io/io.go:461.6-461.18: is implemented by pointer type *SectionReader
gomaster/src/io/io.go:77.6-77.11: implements Reader
gomaster/src/mime/multipart/formdata.go:160.6-160.9: is implemented by interface type mime/multipart.File
gomaster/src/mime/multipart/formdata.go:169.6-169.22: is implemented by struct type mime/multipart.sectionReadCloser
gomaster/src/net/http/fs.go:93.6-93.9: is implemented by interface type net/http.File
gomaster/src/os/exec/exec.go:562.6-562.14: is implemented by struct type os/exec.closeOnce
gomaster/src/os/types.go:16.6-16.9: is implemented by pointer type *os.File
gomaster/src/strings/reader.go:17.6-17.11: is implemented by pointer type *strings.Reader

Caleb Spare

unread,
May 15, 2019, 3:39:10 PM5/15/19
to Sam Mortimer, golang-nuts
To summarize, there are three main concrete types in the standard
library that provide ReadSeeker functionality:

*os.File
*bytes.Reader
*strings.Reader
> --
> You received this message because you are subscribed to the Google Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/a4bdba7c-d79c-46e8-9cfc-302444de8262%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

White Hexagon

unread,
May 15, 2019, 4:28:46 PM5/15/19
to golang-nuts
bytes.Reader is what I was looking for, thanks all!

Seems like if it this information can be generated, then it should probably be included in the main documentation?  I don't know how anyone new to the language would ever work that out otherwise.

I have vscode 1.33, which support guru (using .0.9.2 of the go tools), but I don't see the option for 'implements'.

macos 10.12.4
go 1.12.5

Cheers
Peter

Agniva De Sarker

unread,
May 16, 2019, 3:50:04 AM5/16/19
to golang-nuts
You can see the documentation by enabling type analysis in godoc. See https://golang.org/lib/godoc/analysis/help.html. Also see https://github.com/golang/go/issues/20131

White Hexagon

unread,
May 16, 2019, 4:15:56 AM5/16/19
to golang-nuts
Thanks. Tools are fine, but a new developer has to know about them.  So I think it would still be super useful if golang.org documentation had this information already generated.  In bytes.Reader I should be able to see 'Implements ReadSeeker etc', and in ReadSeeker I should be able to see 'Implemented by bytes.Reader etc'.

Cheers
Peter

Michael Jones

unread,
May 16, 2019, 3:25:14 PM5/16/19
to White Hexagon, golang-nuts
The magical Go phrase is "implicitly implements." What you want is to make that explicit in the documentation.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--
Michael T. Jones
michae...@gmail.com

Agniva De Sarker

unread,
May 16, 2019, 3:33:38 PM5/16/19
to golang-nuts
godoc _is_ the tool serving golang.org (Although now it's split into 2). You just need to enable that flag to get the results you want. Enabling it by default in golang.org is https://github.com/golang/go/issues/11251. Feel free to subscribe to that.
Reply all
Reply to author
Forward
0 new messages