本文整理汇总了Golang中encoding/json.HTMLEscape函数的典型用法代码### 示例。如果您正苦于以下问题:Golang HTMLEscape函数的具体用法?Golang HTMLEscape怎么用?Golang HTMLEscape使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。
在下文中一共展示了HTMLEscape函数的14个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。
示例1: main
func main() {
src, _ := json.Marshal(&Message{"annnnn", "extt<tt>"})
var b bytes.Buffer
//json.Compact(&b, src)
json.HTMLEscape(&b, src)
b.WriteTo(os.Stdout)
}
开发者ID:hyndio,项目名称:hyd.me,代码行数:7,代码来源:jtest.go
示例2: ServeHTTP
// ServeHTTP shows the current plans in the query cache.
func (plr *Planner) ServeHTTP(response http.ResponseWriter, request *http.Request) {
if err := acl.CheckAccessHTTP(request, acl.DEBUGGING); err != nil {
acl.SendError(response, err)
return
}
if request.URL.Path == "/debug/query_plans" {
keys := plr.plans.Keys()
response.Header().Set("Content-Type", "text/plain")
response.Write([]byte(fmt.Sprintf("Length: %d\n", len(keys))))
for _, v := range keys {
response.Write([]byte(fmt.Sprintf("%#v\n", v)))
if plan, ok := plr.plans.Peek(v); ok {
if b, err := json.MarshalIndent(plan, "", " "); err != nil {
response.Write([]byte(err.Error()))
} else {
response.Write(b)
}
response.Write(([]byte)("\n\n"))
}
}
} else if request.URL.Path == "/debug/vschema" {
response.Header().Set("Content-Type", "application/json; charset=utf-8")
b, err := json.MarshalIndent(plr.VSchema().Keyspaces, "", " ")
if err != nil {
response.Write([]byte(err.Error()))
return
}
buf := bytes.NewBuffer(nil)
json.HTMLEscape(buf, b)
response.Write(buf.Bytes())
} else {
response.WriteHeader(http.StatusNotFound)
}
}
开发者ID:dumbunny,项目名称:vitess,代码行数:35,代码来源:planner.go
示例3: thJsonify
func thJsonify(v interface{}) html.JS {
bs, err := json.Marshal(v)
assert(err)
buf := new(bytes.Buffer)
json.HTMLEscape(buf, bs)
return html.JS(buf.String())
}
开发者ID:BurntSushi,项目名称:lcmweb,代码行数:8,代码来源:template_helpers.go
示例4: TestHTMLEscape
func TestHTMLEscape(t *testing.T) {
var b, want bytes.Buffer
m := `{"M":"<html>foo &` + "\xe2\x80\xa8 \xe2\x80\xa9" + `</html>"}`
want.Write([]byte(`{"M":"\u003chtml\u003efoo \u0026\u2028 \u2029\u003c/html\u003e"}`))
json.HTMLEscape(&b, []byte(m))
if !bytes.Equal(b.Bytes(), want.Bytes()) {
t.Errorf("HTMLEscape(&b, []byte(m)) = %s; want %s", b.Bytes(), want.Bytes())
}
}
开发者ID:nolenroyalty,项目名称:bangarang,代码行数:9,代码来源:encode_test.go
示例5: WriteStr
func (w *JsonWriter) WriteStr(name, val string) *JsonWriter {
w.checkSeperator()
val = strings.Replace(val, "\"", "\\\"", -1)
w.writeIdent(name)
w.buffer.WriteByte('"')
json.HTMLEscape(&w.buffer, []byte(val))
w.buffer.WriteByte('"')
return w
}
开发者ID:boombuler,项目名称:tron2go,代码行数:9,代码来源:jsonwriter.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng