本文整理汇总了Golang中html.EscapeString函数的典型用法代码示例。如果您正苦于以下问题:Golang EscapeString函数的具体用法?Golang EscapeString怎么用?Golang EscapeString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了EscapeString函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: StoreMessage

func (h *Handler) StoreMessage(c web.C, w http.ResponseWriter, r *http.Request) {
    room := r.PostFormValue("room")
    if room == "" {
        fmt.Fprintf(w, response.New().WithError(errors.New("No room specified. Skipping.")).Json())
        return
    }

    msg := map[string]interface{}{
        "room":    html.EscapeString(r.PostFormValue("room")),
        "author":  html.EscapeString(r.PostFormValue("author")),
        "message": html.EscapeString(r.PostFormValue("message")),
        "at":      serializer.ParseJavaScriptTime(r.PostFormValue("time")),
    }

    logForReq(c, fmt.Sprintf("Inserting %s", msg))

    message, err := h.DB.InsertMessage(msg)

    if err != nil {
        errMsg := fmt.Sprintf("Could not insert message %s: %s", msg, err.Error())
        http.Error(w, response.New().WithError(errors.New(errMsg)).Json(), 500)
        return
    }
    fmt.Fprintf(w, response.New().WithMessage(message).Json())
}

开发者ID:parkr,项目名称:gossip,代码行数:25,代码来源:handler.go

示例2: Format

func (HTMLFormatter) Format(element Element) string {
    switch el := element.(type) {
    case *Document:
        return `<!DOCTYPE html>
<html>
<head>
` + HTML.documentHeader(el) + `
</head>
<body>
<div class="container">
<h1 class="page-header">` + html.EscapeString(el.Title) + `</h1>
` + HTML.formatContent(el.Contents()) + `
</div>
<script src="/js/bootstrap.js" async></script>
</body>
</html>`
    case *Italic:
        return "<em>" + HTML.formatContent(el.Contents()) + "</em>"
    case *Bold:
        return "<strong>" + HTML.formatContent(el.Contents()) + "</strong>"
    case *LineBreak:
        return "<br>"
    case *Paragraph:
        return "<p>" + HTML.formatContent(el.Contents()) + "</p>"
    case *Image:
        return "<img src=\"" + html.EscapeString(el.URL) + "\" alt=\"" + html.EscapeString(el.Description) + "\" title=\"" + html.EscapeString(el.Description) + "\">"
    case *Link:
        return "<a href=\"" + html.EscapeString(el.URL) + "\">" + HTML.formatContent(el.Contents()) + "</a>"
    case *LeafElement:
        return html.EscapeString(el.Text)
    case *Article:
        return "<article><h1>" + el.Title + " <small>" + el.Timestamp.Format("15:04 2 Jan 2006") + "</small></h1>\n" + HTML.formatContent(el.Contents()) + "</article>"
    }
    return fmt.Sprintf("%#v", element)
}

开发者ID:Nightgunner5,项目名称:go.cms,代码行数:35,代码来源:html.go

示例3: getPackageNodes

func getPackageNodes(goCode []ParsedCode) (packageNodes []graph.PackageNode) {

    packagesMap := make(map[string]*graph.PackageNode)

    //Map the files to their graph.PackageNode
    for _, parsedCode := range goCode {

        //Get packageNode from map
        nodePtr := packagesMap[parsedCode.PackageName()]
        if nodePtr == nil {
            node := graph.CreatePackageNode(
                html.EscapeString(parsedCode.PackageName()),
                html.EscapeString(parsedCode.PackagePath()),
                nil)
            nodePtr = &node
        }

        //add row
        nodePtr.AddPackageNodeRow(graph.CreatePackageNodeRow(
            html.EscapeString(parsedCode.FileName()),
            htmlEscapeStringArray(parsedCode.Functions()),
            htmlEscapeStringArray(parsedCode.Types()),
            htmlEscapeStringArray(parsedCode.Variables())))

        //put back in map
        packagesMap[parsedCode.PackageName()] = nodePtr
    }

    //Take the graph.PackageNode out of the map and put in an array.
    for _, packageNode := range packagesMap {
        packageNodes = append(packageNodes, *packageNode)
    }

    return packageNodes
}

开发者ID:CodeHipster,项目名称:go-code-visualizer,代码行数:35,代码来源:cv-formatter.go

示例4: ServeHTTP

func (sh *SyncHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
    sh.lk.Lock()
    defer sh.lk.Unlock()

    fmt.Fprintf(rw, "<h1>%s to %s Sync Status</h1><p><b>Current status: </b>%s</p>",
        sh.fromName, sh.toName, html.EscapeString(sh.status))

    fmt.Fprintf(rw, "<h2>Stats:</h2><ul>")
    fmt.Fprintf(rw, "<li>Blobs copied: %d</li>", sh.totalCopies)
    fmt.Fprintf(rw, "<li>Bytes copied: %d</li>", sh.totalCopyBytes)
    if !sh.recentCopyTime.IsZero() {
        fmt.Fprintf(rw, "<li>Most recent copy: %s</li>", sh.recentCopyTime.Format(time.RFC3339))
    }
    fmt.Fprintf(rw, "<li>Copy errors: %d</li>", sh.totalErrors)
    fmt.Fprintf(rw, "</ul>")

    if len(sh.blobStatus) > 0 {
        fmt.Fprintf(rw, "<h2>Current Copies:</h2><ul>")
        for blobstr, sfn := range sh.blobStatus {
            fmt.Fprintf(rw, "<li>%s: %s</li>\n",
                blobstr, html.EscapeString(sfn.String()))
        }
        fmt.Fprintf(rw, "</ul>")
    }

    if len(sh.recentErrors) > 0 {
        fmt.Fprintf(rw, "<h2>Recent Errors:</h2><ul>")
        for _, te := range sh.recentErrors {
            fmt.Fprintf(rw, "<li>%s: %s</li>\n",
                te.t.Format(time.RFC3339),
                html.EscapeString(te.err.Error()))
        }
        fmt.Fprintf(rw, "</ul>")
    }
}

开发者ID:t3rm1n4l,项目名称:camlistore,代码行数:35,代码来源:sync.go

示例5: handleDump

// HTTP handler for _dump
func (h *handler) handleDump() error {
    viewName := h.PathVar("view")
    base.LogTo("HTTP", "Dump view %q", viewName)
    opts := db.Body{"stale": false, "reduce": false}
    result, err := h.db.Bucket.View(db.DesignDocSyncGateway, viewName, opts)
    if err != nil {
        return err
    }
    title := fmt.Sprintf("/%s: “%s” View", html.EscapeString(h.db.Name), html.EscapeString(viewName))
    h.setHeader("Content-Type", `text/html; charset="UTF-8"`)
    h.response.Write([]byte(fmt.Sprintf(
        `<!DOCTYPE html><html><head><title>%s</title></head><body>
        <h1>%s</h1><code>
        <table border=1>
        `,
        title, title)))
    h.response.Write([]byte("\t<tr><th>Key</th><th>Value</th><th>ID</th></tr>\n"))
    for _, row := range result.Rows {
        key, _ := json.Marshal(row.Key)
        value, _ := json.Marshal(row.Value)
        h.response.Write([]byte(fmt.Sprintf("\t<tr><td>%s</td><td>%s</td><td><em>%s</em></td>",
            html.EscapeString(string(key)), html.EscapeString(string(value)), html.EscapeString(row.ID))))
        h.response.Write([]byte("</tr>\n"))
    }
    h.response.Write([]byte("</table>\n</code></html></body>"))
    return nil
}

开发者ID:diesal11,项目名称:sync_gateway,代码行数:28,代码来源:bulk_api.go

最后编辑: kuteng  文档更新时间: 2021-08-26 18:17   作者:kuteng