Apply custom html tag to gin-gonic response

女生的网名这么多〃 提交于 2019-12-11 14:32:08

问题


I'm trying to prettify the response printed trough gin-gonic.

From a go POV, i populate a struct with a string. My scope is to apply html tag to the input string.

// Struct for prettify response
type DocResponse struct {
    Filename string `json:"filename"`
    Url      string `json:"url"`
    Content  string `json:"data"`
}

var response []DocResponse
// iterating data for populate struct
for i := range found {
//NOTE: Apply a <div> tag
    tmp := DocResponse{Filename: found[i], Url: `<div>http://127.0.0.1:8080/data` + found[i] + `</div>`, Content: `**`}
    response = append(response, tmp)
}
elapsed := time.Since(start)
log.Debug("main | Found ", len(found), " in ", elapsed)
// Printing the result
c.HTML(http.StatusOK, "index.html", gin.H{
    "NumResult": len(found), "Seconds": elapsed, "Response": response,
})

The data are print as a simple ASCII string instead of be interpreted as the HTML tag.

I print the data with the following HTML code:

...
      </div>
   {{.Response}}
</div>

The result are a list like the following:

[{/path/path/path/blabla/ <div>http://.etc.etc./path/blabla/</div> ** }]

Does someone know how to apply/render custom HTML tag printed trough gin-gonic?

I'd like to understand how to apply a custom HTML tag (like <href>,<div>,<p> etc) from a simple string printed trough gin-gonic.

来源:https://stackoverflow.com/questions/58204983/apply-custom-html-tag-to-gin-gonic-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!