package main
import (
"flag";
"http";
"io";
"log";
"strings";
"template";
)
var addr = flag.String("addr", ":8000", "http service address")
var fmap = template.FormatterMap{
"html": template.HTMLFormatter,
"url+html": UrlHtmlFormatter,
}
var templ = template.MustParse(templateStr, fmap)
func main() {
flag.Parse();
http.Handle("/", http.HandlerFunc(QR));
err := http.ListenAndServe(*addr, nil);
if err != nil {
log.Exit("ListenAndServe:", err);
}
}
func QR(c *http.Conn, req *http.Request) {
templ.Execute(c);
}
func UrlHtmlFormatter(w io.Writer, v interface{}, fmt string) {
template.HTMLEscape(w, strings.Bytes(http.URLEscape(v.(string))));
}
const templateStr = `
<html>
<body>
{.section @}
Hello, world!
{.end}
</body>
</html>
`