godoc shows methods where they're not defined

64 views
Skip to first unread message

Tamás Gulácsi

unread,
Jun 25, 2017, 3:51:01 AM6/25/17
to golang-nuts
Hi,

Both my local go1.9-beta1, and godoc.org shows BeginTx on *DirectedLob, but that's defined on *conn, a private type!
What I'm doing wrong here?



Thanks,
Tamás Gulácsi

Auto Generated Inline Image 1

Nathan Kerr

unread,
Jun 25, 2017, 6:27:56 AM6/25/17
to golang-nuts
Since *conn is embedded in DirectLob, its method sets are promoted to DirectLob's method sets. Since BeginTx is now part of DirectLob's method sets, it acts like any other member of the method sets would; in this case it is an exported method on DirectLob.

This is a feature because it allows the use of *conn's methods while not allowing direct, external access to *conn. If you want to make only part of *conn's method sets available, don't embed *conn (i.e., give it a name) and write wrappers for the methods you need.

See https://golang.org/ref/spec#Struct_types for embedded field promotion rules.

Tamás Gulácsi

unread,
Jun 25, 2017, 9:46:55 AM6/25/17
to golang-nuts
Thanks!
In retrospect, it's obvious :)
Reply all
Reply to author
Forward
0 new messages