I am working in a Golang project, currently am trying to render some templates but the HTML code of the template is being printed in the browser. My project structure is:
|-app
|---models
|---controller
|---templates
|------index.gohtml
|-main.go
Then, the code that I have in one controller, to render the template is:
func Index(w http.ResponseWriter, req *http.Request, ps httprouter.Params){
var tpl *template.Template
tpl = template.Must(template.ParseGlob("app/templates/*.gohtml"))
err := tpl.ExecuteTemplate(w, "index.gohtml", nil)
if(err!=nil){
fmt.Println("error:",err.Error())
}
However I am not getting any error. But in the browser the code that I have inside index.gohtml
is being printed and not rendered }
checkout net/http/sniff.go. It shows how net/http infers MIME types.
For Html your content can start with :
<!DOCTYPE HTML
<HTML
<HEAD
<SCRIPT
<IFRAME
<H1
<DIV
<FONT
<TABLE
<A
<STYLE
<TITLE
<B
<BODY
<BR
<P
<!--