You create structs like StringNode and HtmlNode that implement the common 
needed operations. 

Imagine a Render() method for a string you convert to html, for an html node 
you render recursively. 

Or similar. If an HtmlNode is not a leaf node it needs recursive operations. 

> On Dec 20, 2021, at 12:52 PM, Michael Ellis <michael.f.el...@gmail.com> wrote:
> 
> 
> 
>> On Monday, December 20, 2021 at 1:33:49 PM UTC-5 ren...@ix.netcom.com wrote:
>> You should use interfaces and a “node” type.
> 
> Hmm, I tried 
> 
> type Node interface {
>         string | []*HtmlTree
> }
> 
> type HtmlTree struct {
>         T     string // html tagname, e.g. 'head'
>         A     string // zero or more html attributes, e.g 'id=1 class="foo"'
>         C     Node   // a slice of content whose elements may be strings or 
> *HtmlTree
>         empty bool   // set to true for empty tags like <br>
> }
> 
> and the compiler said: 
> ./prog.go:21:8: interface contains type constraints.
> 
> (line 21 is the declaration of HtmlTree.C as type Node)
> 
> What's the syntax you have in mind?
> 
> 
>  
> -- 
> 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/c619d54d-5a69-4828-b10b-771722f8f646n%40googlegroups.com.

-- 
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/88DB1537-6360-4D34-96BC-C9F2CEB01C0A%40ix.netcom.com.

Reply via email to