Hey @blangenfeld,
&
's being escaped to &
is actually correct encoding.
Here’s a quick example based on your code to show you that the link actually gets rendered correctly (go to http://localhost:9000):
package main
import (
"html/template"
"log"
"net/http"
)
var tmpl = template.Must(template.New("template").Parse(`
Want: <a href="http://www.google.com?foo=bar&baz=qux">foo</a>
<br />
Got: <a href="{{.}}">foo</a>
`))
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-type", "text/html")
err := tmpl.Execute(w, template.URL("http://www.google.com?foo=bar&baz=qux"))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
})
log.Fatal(http.ListenAndServe(":9000", nil))
}
If you actually wanted to write a link to os.Stdout without the &
encoding, you could simply pass the whole link tag as html into a template instead of what’s just inside of the quotes:
t := template.Must(template.New("template").Parse(`{{.}}`))
err := t.Execute(os.Stdout, template.HTML(`<a href="http://www.google.com?foo=bar&baz=qux">foo</a>`))
if err != nil {
log.Fatalln(err)
}