问题
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