使用golang模板填充div中的许多HTML元素?

I receive from my frontend a json with a string containing 1 or more HTML elements for example:

"textTop" : "<b>bold</b><div><i>italic</i>..."

I want to use this string to create Html elements inside a div, but I'm not really sure if I can do this with golang templates.

type FooBar struct {
    TextTop    string
}

So I'm currently storing the TextTop in a string, and then displaying it in html with:

        <div>
            {{.TextTop}}
        </div>

But of course this produces the following result in the browser. just a div containing the string, I'm passing.: enter image description here

So should I use a different type for TextTop inside Foobar struct instead of type string, which one? or can I use a golang function that reads all html elements from a string and renders them in the html as part of the DOM and not just a string?

To prevent escaping, declare the field as type template.HTML:

type FooBar struct {
    TextTop    template.HTML
}

See the linked documentation for information about the security risks of using template.HTML.