Hacker News new | ask | show | jobs
by rustyboy 1917 days ago
Let me just clarify, sorry i'm from python, so not very familiar but this feels like a "circular reference". You're implementing a struct CartStore which has methods GetById, and Put. Because interfaces (or contracts) are implicit then it's automatically considered a Cart.

What I don't understand is the return types of these functions, a pointer to a cart's cart member? or an error.

2 comments

Interfaces in Go are implicitely implemented. It means that if a type has the methods defined in the interface, then it implements the interface.

I will update the example because it's confusing !

If you have some time come to the speak with me in the chatbox on the website I can help you understand this.

  cart.Cart
  package.NameInPackage
So the name Cart is an interface, the function/method signatures are indicating that a Cart is being returned but being explicit about the package the interface belongs to with cart.Cart. It's made more confusing since the name cart (lower-c) is being used for both a member variable and the package name in the signature of Put, and it looks like the package name doesn't show up on an explicit line in that chapter to help clarify it.