가 :구글의 '이동'및 범위/기능 golang.org에 주어진 예 서버 중 하나에서
package main
import (
"flag"
"http"
"io"
"log"
"template"
)
var addr = flag.String("addr", ":1718", "http service address") // Q=17, R=18
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(req.FormValue("s"), c)
}
func UrlHtmlFormatter(w io.Writer, v interface{}, fmt string) {
template.HTMLEscape(w, []byte(http.URLEscape(v.(string))))
}
const templateStr = `
<html>
<head>
<title>QR Link Generator</title>
</head>
<body>
{.section @}
<img src="http://chart.apis.google.com/chart?chs=300x300&cht=qr&choe=UTF- 8&chl={@|url+html}"
/>
<br>
{@|html}
<br>
<br>
{.end}
<form action="/" name=f method="GET"><input maxLength=1024 size=70
name=s value="" title="Text to QR Encode"><input type=submit
value="Show QR" name=qr>
</form>
</body>
</html>
`
왜 template.HTMLEscape(w, []byte(http.URLEscape(v.(string))))
이 UrlHtmlFormatter
에 포함되어? "url+html"
에 직접 연결할 수없는 이유는 무엇입니까?
또한 어떻게 func QR을 매개 변수 값을 허용하도록 변경할 수 있습니까? 무엇을 할 내가 원하는 것은 기능 template.HTMLEscape
에 대한
내가 묻는 질문에 대한 모든 답변에 감사드립니다 ... – danwoods