How do you embed two types of the same name in a struct? For instance:
type datastore {
*sql.Store
*file.Store
}
Results in duplicate field Store
. I know this makes sense, since you wouldn't be able to refer to the embedded field ds.Store
but how do you accomplish this anyway?
To clarify, I want to implement an interface with datastore
. For that both structs are needed as their methods complement each other to create the interface. What alterantives do I have?
Use a type alias, example:
type sqlStore = sql.Store // this is a type alias
type datastore {
*sqlStore
*file.Store
}
A type alias doesn’t create a new distinct type different from the type it’s created from. It just introduces an alias name sqlStore
, an alternate spelling, for the type denoted by sql.Store
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With