本文整理汇总了Golang中html/template.JSEscapeString函数的典型用法代码示例。如果您正苦于以下问题:Golang JSEscapeString函数的具体用法?Golang JSEscapeString怎么用?Golang JSEscapeString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JSEscapeString函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: JSEscape
// 安全过滤
func JSEscape(topics []*model.Topic) []*model.Topic {
for i, topic := range topics {
topics[i].Title = template.JSEscapeString(topic.Title)
topics[i].Content = template.JSEscapeString(topic.Content)
}
return topics
}
开发者ID:BillyMC,项目名称:studygolang,代码行数:8,代码来源:topic.go
示例2: handleJsError
func handleJsError(jsCode string, err error) string {
if err != nil {
fmt.Fprintln(os.Stderr, err)
return `console.error("` + template.JSEscapeString(err.Error()) + `");`
}
return jsCode
}
开发者ID:wutaizeng,项目名称:kapacitor,代码行数:7,代码来源:gopherjs_http.go
示例3: render
func (t *Template) render(rctx core.RenderContext) string {
b := &bytes.Buffer{}
// Update functions for current rendering context.
t.tmpl.Funcs(map[string]interface{}{
"slot": func(name, elt string) template.HTML {
s := t.node.Slot(name)
if elt == "" {
return template.HTML(s.Node().Render(rctx))
}
return template.HTML(fmt.Sprintf("<%s id='%s'>%s</%s>", elt, s.ID(), s.Node().Render(rctx), elt))
},
"event": func(name string) template.JS {
return template.JS(fmt.Sprintf("stdweb.events.onClick('%s', '%s', event)", template.JSEscapeString(t.node.ID()), template.JSEscapeString(name)))
},
})
err := t.tmpl.Execute(b, &tplData{
ID: t.node.ID(),
RunID: rctx.RunID(),
UpdateID: rctx.UpdateID(),
Data: t.data,
})
if err == nil {
return b.String()
}
return html.EscapeString(err.Error())
}
开发者ID:Palats,项目名称:stdweb,代码行数:29,代码来源:template.go
示例4: serveLive
// serveLive serves reloader and serves the web socket connection
func (server *Server) serveLive(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "must-revalidate, no-cache")
switch path.Base(r.URL.Path) {
case "~pkg.js":
w.Header().Set("Content-Type", "application/javascript")
w.Write([]byte(jspackage))
origurl, err := url.ParseRequestURI(r.RequestURI)
origpath := r.RequestURI
if err != nil && origurl != nil {
origpath = origurl.Path
}
rootpath := template.JSEscapeString(path.Dir(origpath))
w.Write([]byte(strings.Replace(jsreloader, rootPathMarker, rootpath, -1)))
case "~pkg.json":
server.info(w, r)
case "~pkg.css":
// this will be handled by reloader
w.Header().Set("Content-Type", "text/css; charset=utf-8")
w.WriteHeader(http.StatusOK)
w.Write([]byte{'\n'})
case "~live":
server.socket.ServeHTTP(w, r)
default:
server.bundle.ServeFile(w, r)
}
}
开发者ID:raintreeinc,项目名称:livepkg,代码行数:30,代码来源:server.go
示例5: Example_escape
func Example_escape() {
const s = `"Fran & Freddie's Diner" <[email protected]>`
v := []interface{}{`"Fran & Freddie's Diner"`, ' ', `<[email protected]>`}
fmt.Println(template.HTMLEscapeString(s))
template.HTMLEscape(os.Stdout, []byte(s))
fmt.Fprintln(os.Stdout, "")
fmt.Println(template.HTMLEscaper(v...))
fmt.Println(template.JSEscapeString(s))
template.JSEscape(os.Stdout, []byte(s))
fmt.Fprintln(os.Stdout, "")
fmt.Println(template.JSEscaper(v...))
fmt.Println(template.URLQueryEscaper(v...))
// Output:
// "Fran & Freddie's Diner" <[email protected]>
// "Fran & Freddie's Diner" <[email protected]>
// "Fran & Freddie's Diner"32<[email protected]>
// \"Fran & Freddie\'s Diner\" \[email protected]\x3E
// \"Fran & Freddie\'s Diner\" \[email protected]\x3E
// \"Fran & Freddie\'s Diner\"32\[email protected]\x3E
// %22Fran+%26+Freddie%27s+Diner%2232%3Ctasty%40example.com%3E
}
开发者ID:wheelcomplex,项目名称:go-1,代码行数:26,代码来源:example_test.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng