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

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

示例1: renderEntriesList

func renderEntriesList(entries []Entry) template.HTML {
    buf := &bytes.Buffer{}
    buf.WriteString(`
<div class="row" id="entries">`)
    for _, e := range entries {
        title := template.HTMLEscapeString(e.Title)
        content := template.HTMLEscapeString(e.Content)
        content = strings.Replace(content, "\n", "<br />\n", 0)
        fmt.Fprintf(buf, `
    <div class="panel panel-primary entry">
        <div class="entry-title">タイトル: <a href="/diary/entry/%d">%s</a></div>
        <div class="entry-content">
%s
        </div>
    `, e.ID, title, content)
        if e.Private {
            buf.WriteString(`<div class="text-danger entry-private">範囲: 友だち限定公開</div>`)
        }
        fmt.Fprintf(buf, `
        <div class="entry-created-at">更新日時: %s</div>
        <div class="entry-comments">コメント: %d件</div>
    </div>`,
            e.CreatedAt.Format("2006-01-02 15:04:05"), e.NumComments)
    }
    buf.WriteString(`</div>`)
    return template.HTML(buf.String())
}

开发者ID:methane,项目名称:isucon5-qualifying-go,代码行数:27,代码来源:app.go

示例2: login

func login(w http.ResponseWriter, r *http.Request) {
    fmt.Println("method:", r.Method) //获取请求的方法
    if r.Method == "GET" {
        crutime := time.Now().Unix()
        h := md5.New()
        io.WriteString(h, strconv.FormatInt(crutime, 10))
        token := fmt.Sprintf("%x", h.Sum(nil))
        fmt.Println("token", token)
        t, _ := template.ParseFiles("login.gtpl")
        t.Execute(w, token)
    } else {
        //请求的是登陆数据,那么执行登陆的逻辑判断
        r.ParseForm()
        token := r.Form.Get("token")
        if token != "" {
            //验证 token 的合法性
        } else {
            //不存在 token 报错
        }
        fmt.Println("username length:", len(r.Form["username"][0]))
        fmt.Println("username:",
            template.HTMLEscapeString(r.Form.Get("username"))) //输出到服务器端
        fmt.Println("password:",
            template.HTMLEscapeString(r.Form.Get("password")))
        template.HTMLEscape(w, []byte(r.Form.Get("username"))) //输出到客户端
    }
}

开发者ID:NicholeGit,项目名称:go,代码行数:27,代码来源:main.go

示例3: login

func login(w http.ResponseWriter, r *http.Request) {
    fmt.Println("method: ", r.Method)
    if r.Method == "GET" {
        cruTime := time.Now().Unix()
        h := md5.New()
        io.WriteString(h, strconv.FormatInt(cruTime, 10))
        token := fmt.Sprintf("%x", h.Sum(nil))

        t, _ := template.ParseFiles("04-02-03-duplicate-prevention.gtpl")
        t.Execute(w, token)

    } else {
        // log in request
        r.ParseForm()
        token := r.Form.Get("token")

        if token != "" {
            // check token validity
            fmt.Println("TODO: check if the token is valid: %s\n", token)
        } else {
            // give error if no token
            fmt.Println("TODO: handle error as token is not valid!")
        }

        fmt.Printf("Username length: %v\n", len(r.Form["username"][0]))
        fmt.Printf("Username       : %v\n", template.HTMLEscapeString(r.Form.Get("username")))
        fmt.Printf("password       : %v\n", template.HTMLEscapeString(r.Form.Get("password")))
        template.HTMLEscape(w, []byte(r.Form.Get("username")))
    }
}

开发者ID:agilecreativity,项目名称:go-playground,代码行数:30,代码来源:04-02-03-duplicate-prevention.go

示例4: handlerCreateAccount

func handlerCreateAccount(w http.ResponseWriter, r *http.Request) {
    if r.Method == "GET" {
        giveFormTemplate("static/create_account.html", w)
    } else if r.Method == "POST" {
        r.ParseForm()
        email := string(template.HTMLEscapeString(r.Form.Get("email")))
        if !validEmail(email) {
            fmt.Fprintf(w, "Please input a valid email")
            return
        }
        username := string(template.HTMLEscapeString(r.Form.Get("username")))
        if username == "" {
            fmt.Fprintf(w, "Username can't be blank")
            return
        }
        password := r.Form.Get("password")
        if !validPassword(password) {
            fmt.Fprintln(w, "Given password does not comply with ",
                "given password directives")
            return
        }
        password = getSha512B64(r.Form.Get("password"))
        if err := AddUser(email, password, username); err != nil {
            fmt.Fprintf(w, "Mail or username already in use or %s\n", err)
            return
        }
        http.Redirect(w, r, "/created", http.StatusFound)
    }
}

开发者ID:jenarvaezg,项目名称:ctff,代码行数:29,代码来源:handlers.go

示例5: login

func login(w http.ResponseWriter, r *http.Request) {
    fmt.Println("method:", r.Method)
    if r.Method == "GET" {
        crutime := time.Now().Unix()
        fmt.Println("crutime = ", crutime)
        h := md5.New()
        s := strconv.FormatInt(crutime, 10)
        fmt.Println("s = ", s)
        io.WriteString(h, s)
        fmt.Println("h's md5 = ", h.Sum(nil))
        token := fmt.Sprintf("%x", h.Sum(nil))
        t, _ := template.ParseFiles("login.gtpl")
        t.Execute(w, token)
    } else {
        r.ParseForm()
        token := r.Form.Get("token")
        if token != "" {
            fmt.Println("token is ", token)
        } else {
            fmt.Println("token is not exists ")
        }
        fmt.Println("username length:", len(r.Form["username"][0]))
        fmt.Println("username:", template.HTMLEscapeString(r.Form.Get("username")))
        fmt.Println("password:", template.HTMLEscapeString(r.Form.Get("password")))
        template.HTMLEscape(w, []byte(r.Form.Get("username")))
    }
}

开发者ID:vinniey,项目名称:findme.biz,代码行数:27,代码来源:http.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng