go - struct first line is just an interface, what does it mean? -


this question has answer here:

i come across code in go:

type mytype struct {   interfacename   var1  clientinterface1   var2  clientinterface2   id    int } 

what first field mean?

mostly, how sort of inheritance (by composition rather inheritance) achieved in go. check out: https://golang.org/doc/effective_go.html#embedding

this grant outer type (mytype) access inner type's receiver methods (the assigned struct{} since interface).

from go effective:

there's important way in embedding differs subclassing. when embed type, methods of type become methods of outer type, when invoked receiver of method inner type, not outer one

thanks @flimzy , @md2perpe

also, defines anonymous field, variable name same type name.


Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -