FAQ
Your method receivers have a mix of pointer and non pointer receivers.
Letting "D" stand for "Database":

func (d D) GetDatabase() etc
func (d *D) Connect() etc

Note that some of these are D, others are *D with a star.

The thing is that *D gets the methods that are defined by D, but not
vice versa. (http://golang.org/ref/spec#Method_sets says that "The
method set of the corresponding pointer type *T is the set of all
methods declared with receiver *T or T (that is, it also contains the
method set of T)")

Thus, *D has a Connect method AND a GetDatabase method (ignoring the
others for now). D without a * only has a GetDatabase method, not a
Connect method.

The Connector interface includes the Connect method. Thus, *D
satisfies this interface, but D does not.

Your original NewDatabase function returns a D, not a *D, which the
compiler correctly rejects, because a D is not a Connector.

The best fix is to make all of your receivers *D, not a mix of D and
*D. Even after that, I'd still return a *D instead of a D.

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 13 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedSep 4, '15 at 2:12a
activeSep 5, '15 at 12:23a
posts13
users7
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase