Did you try something like this? What errors did you get? type Event interface { ... }
type EventImpl struct { ... } eventSlice:=make([]Event,0) eventMap:=make(map[string]Event) event:=&EventImpl{} eventSlice=append(eventSlice,event) eventMap["key"]=event On Thu, Aug 30, 2018 at 10:57 AM Eric Raymond <e...@thyrsus.com> wrote: > > I apologize if this seems like an elementary question, but web searches and > reading the Go documentation is not turning up an answer. > > I'm in the process of translating reposurgeon, an editor for version-control > histories, from Python into Go for improved performance, .The central data > structure is Repository, which consists mainly of a list of events such as > commits and tags. In Python, I use the language's late binding and simply > declare a list of containing multiple object types named Commit, Tag, etc. > There are also a number of lookup maps pointing at objects in the main event > list. Because objects in Pytron are passed by reference everything is fairly > straightforward. > > I'm trying to translate this to Go in a type-safe way. To do this, I need to > be able to write two declarations: "Slice of pointers to objects satisfying > the Event interface" and "map of string keys to pointers to objects > satisfying the Event interface". My attempts so far have yielded very > cryptic error messages and no success. > > Is it actually possible to restrict the main list's polymorphism in this way > and avoid casts? > > > > > > > > > -- > 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+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.