I've got a package, github.com/Michael-F-Ellis/goht, that supports creating 
HTML docs in Go.  It works well, for my purposes at least, but I've always 
been bothered by having to use []interface{} to define the struct member, 
C, that supports recursion.

type HtmlTree struct {
        T     string        // html tagname, e.g. 'head'
        A     string        // zero or more html attributes, e.g 'id=1 
class="foo"'
        C     []interface{} // a slice of content whose elements may be 
strings or *HtmlTree
        empty bool          // set to true for empty tags like <br>
}

I've created a minimal extract of the package on the playground at 
https://go.dev/play/p/-_7JKRZYLC_J?v=gotip.  Assuming the new generics can 
support constraining HtmlTree.C to be a slice of string | *HtmlTree, what 
is the right syntax for doing so?

Thanks!


-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/a8817b41-85dd-4fd1-a946-00764713c008n%40googlegroups.com.

Reply via email to