<p>I am trying to implement a custom default-http image for my Kubernetes Cluster. I only got 2 requirements:</p>

<ul>
<li><p>Any image is permissable as long as:</p>

<ol>
<li>It serves a 404 page at /</li>
<li>It serves 200 on a /healthz endpoint</li>
</ol></li>
</ul>

<p>As of right now, that what I got:</p>

<pre><code>  1 package main
  2
  3 import (
  4     "fmt"
  5     "net/http"
  6     "html/template"
  7 )
  8
  9 func main() {
 10     http.HandleFunc("/healthz", healhtzHandler)
 11     http.HandleFunc("/",errorHandler)
 12     http.ListenAndServe(":8000", nil)
 13 }
 14
 15 func healhtzHandler(w http.ResponseWriter, r *http.Request) {
 16     fmt.Fprint(w, "Really healthy")
 17 }
 18
 19 type Person struct {
 20     UserName string
 21 }
 22
 23 func errorHandler(w http.ResponseWriter, r *http.Request) {
 24     w.WriteHeader(404)
 25     t := template.New("fieldname example")
 26     t, _ = t.Parse("&lt;h2&gt;hello {{.UserName}}!&lt;/h2&gt;")
 27     p := Person{UserName: "Astaxie"}
 28     t.Execute(w, p)
 29 }
</code></pre>

<p>It all works as expected, except that my main goal here is to display a cool 404 error page, so I will need to use Bootstrap, cool tags and etc. But this code always execute the template inside a <code>&lt;pre&gt;&lt;/pre&gt;</code> tag.</p>

<pre><code>&lt;html&gt;
&lt;head&gt;&lt;/head&gt;
&lt;body&gt;
&lt;pre style="word-wrap: break-word; white-space: pre-wrap;"&gt;
&amp;lt;h2&amp;gt;hello Astaxie!&amp;lt;/h2&amp;gt;
&lt;/pre&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>and it ruins everything I want to do. How do I solve this?</p>

CESCO
<p>Based on this <a href="https://golang.org/pkg/html/template/" rel="nofollow">documentation for template</a>, I think you might want to use "text/template" instead of "html/template". </p>

<p>That page says:</p>

<blockquote>
  <p>The contextual autoescaping in html/template produces safe, escaped HTML output </p>
</blockquote>

<p>While:</p>

<pre><code>import "text/template"
...
t, err := template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)
err = t.ExecuteTemplate(out, "T", "&lt;script&gt;alert('you have been pwned') /script&gt;")
</code></pre>

<p>produces
<code>Hello, &lt;script&gt;alert('you have been pwned')&lt;/script&gt;!</code></p>
