当前位置: 首页>>代码示例>>Golang>>正文


Golang template.HTMLEscapeString函数代码示例

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


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

示例6: Sign

func (p *PageIndex) Sign(w http.ResponseWriter, r *http.Request) {
	if r.Method != "POST" {
		p.Body = "不支持这种请求方式: " + fmt.Sprintf("%v", r.Method)
		p.Template = "index/error.html"
		return
	}

	entry := NewGuestBook()
	entry.Name = p.POST["name"]
	entry.Message = p.POST["message"]

	if entry.Name == "" {
		entry.Name = "Some dummy who forgot a name"
	}
	if entry.Message == "" {
		entry.Message = "Some dummy who forgot a message."
	}

	entry.Name = template.HTMLEscapeString(entry.Name)
	entry.Message = template.HTMLEscapeString(entry.Message)

	mgo := Middleware.Get("db").(*helper.Mongo)
	coll := mgo.C(ColGuestBook)

	if err := coll.Insert(entry); err != nil {
		p.Body = "数据库错误:" + fmt.Sprintf("%v", err)
		p.Template = "index/error.html"
		return
	} else {
		http.Redirect(w, r, "/", http.StatusFound)
	}

}
开发者ID:golangers,项目名称:samples,代码行数:33,代码来源:index.go

示例7: MarshalJSON

func (r *Result) MarshalJSON() ([]byte, error) {
	return json.Marshal(
		&map[string]string{
			"z": template.HTMLEscapeString(r.Z),
			"m": template.HTMLEscapeString(r.M),
			"p": template.HTMLEscapeString(r.P)})
}
开发者ID:rhcarvalho,项目名称:shenmeci,代码行数:7,代码来源:web.go

示例8: rejectWhereEmpty

func rejectWhereEmpty(key string, solutions []map[string]rdf.Term) []map[string]interface{} {
	// TODO clean up this function; choose another name too..
	included := make([]map[string]interface{}, 1)
	for _, m := range solutions {
		if m[key] != nil {
			tm := make(map[string]interface{})
			for k, v := range m {
				term := v.Serialize(rdf.Turtle)
				if k != "g" && k != "p" && strings.HasPrefix(term, "<"+conf.BaseURI) {

					// URL without enclosing angle brackets
					link := strings.Trim(term, "<>")

					if conf.UI.FetchLiterals {
						link = fmt.Sprintf("<div class='relative'><a class=\"resource-link\" href='%v'>%v</a><div class=\"tooltip\"><strong>%s</strong><div class='literals'>...</div></div></div>",
							link, template.HTMLEscapeString(term), template.HTMLEscapeString(term))
					} else {
						link = fmt.Sprintf("<a href='%v'>%v</a>",
							link, template.HTMLEscapeString(term))
					}

					tm[k] = template.HTML(link)
				} else {
					if conf.Vocab.Enabled {
						tm[k] = prefixify(&conf.Vocab.Dict, term)
					} else {
						tm[k] = term
					}
				}
			}
			included = append(included, tm)
		}
	}
	return included
}
开发者ID:knakk,项目名称:fenster,代码行数:35,代码来源:utils.go

示例9: login

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

		t, _ := template.ParseFiles("login.html")
		t.Execute(w, token)
	} else {
		r.ParseForm()
		token := r.Form.Get("token")
		if token != "" {
			Println("标识:", token)
			// 验证合法性
		} else {
			Println("标识:未获取")
			// 报错
		}
		Println(r)
		Println("用户名长度:", len(r.Form["username"][0]))
		Println("用户名:", template.HTMLEscapeString(r.Form.Get("username")))
		Println("密码:", template.HTMLEscapeString(r.Form.Get("password")))
		template.HTMLEscape(w, []byte(r.Form.Get("username")))
	}
}
开发者ID:kingfree,项目名称:haut,代码行数:27,代码来源:web.go

示例10: renderCommentsOfFriends

func renderCommentsOfFriends(comments []Comment) template.HTML {
	buf := &bytes.Buffer{}
	buf.WriteString(`
  <div class="col-md-4">
    <div>あなたの友だちのコメント</div>
    <div id="friend-comments">`)

	for _, c := range comments {
		cowner := getUser(c.UserID)
		eowner := getUser(c.EntryOwnerID)
		comment := c.Comment
		if len(comment) > 30 {
			comment = comment[:27] + "..."
		}
		fmt.Fprintf(buf, `
      <div class="friend-comment">
        <ul class="list-group">
          <li class="list-group-item comment-from-to"><a href="/profile/%s">%sさん</a>から<a href="/profile/%s">%sさん</a>へのコメント:</li>
          <li class="list-group-item comment-comment">%s</li>
          <li class="list-group-item comment-created-at">投稿時刻:%s</li>
        </ul>
      </div>`, cowner.AccountName, template.HTMLEscapeString(cowner.NickName), eowner.AccountName, template.HTMLEscapeString(eowner.NickName),
			template.HTMLEscapeString(comment), c.CreatedAt.Format("2006-01-02 15:04:05"))
	}
	buf.WriteString(`</div></div>`)
	return template.HTML(buf.String())
}
开发者ID:methane,项目名称:isucon5-qualifying-go,代码行数:27,代码来源:app.go

示例11: 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("login.gtpl")

		t.Execute(w, token)
	} else {
		r.ParseForm()

		token := r.Form.Get("token")

		if token != "" {
			// check token validity
		} else {
			// give error if no 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:chizhovdee,项目名称:GoHttp,代码行数:31,代码来源:server.go

示例12: index

func index(w http.ResponseWriter, r *http.Request, folder string) {
	r.ParseForm()
	fmt.Println(r.Form)
	fmt.Println("path", r.URL.Path)
	fmt.Println("scheme", r.URL.Scheme)
	fmt.Println(r.Form["url_long"])
	for k, v := range r.Form {
		fmt.Println("key:", k)
		fmt.Println("val:", strings.Join(v, ""))
	}

	fi, err := ListDir(folder)
	if err != nil {
		fmt.Println("Error", err)
	}
	var result = ""
	for _, f := range fi {
		//		d := "-"
		if f.IsDir() {
			continue
		}
		result += "<a href=/open/" + template.HTMLEscapeString(f.Name()) + ">" + template.HTMLEscapeString(f.Name()) + "</a><br>"
	}

	fmt.Fprint(w, result)
}
开发者ID:yaotian,项目名称:easymarkdown,代码行数:26,代码来源:main.go

示例13: doLogin

func doLogin(w http.ResponseWriter, r *http.Request) {
	fmt.Println("method:", r.Method) //リクエストを取得するメソッド

	sess := globalSessions.SessionStart(w, r)
	r.ParseForm()

	if r.Method == "GET" {
		t, _ := template.ParseFiles("templates/login.tmpl.html")
		t.Execute(w, sess.Get("username"))
	} else {
		username := template.HTMLEscapeString(r.Form.Get("username"))
		token := r.Form.Get("token")
		if token != "" {
			//tokenの合法性を検証します。
		} else {
			//tokenが存在しなければエラーを出します。
		}

		sess.Set("username", username)

		// r.FormValue["username"]と書くことでr.ParseForm()を省略可能
		fmt.Println("username length:", len(r.Form["username"][0]))
		fmt.Println("username:", username) //サーバ側に出力します。
		fmt.Println("password:", template.HTMLEscapeString(r.Form.Get("password")))

		http.Redirect(w, r, "/", 302)
	}
}
开发者ID:kyokomi,项目名称:webappsample,代码行数:28,代码来源:main.go

示例14: printFunctionSourceLine

// printFunctionSourceLine prints a source line and the corresponding assembly.
func printFunctionSourceLine(w io.Writer, fn *node, assembly nodes, rpt *Report) {
	if len(assembly) == 0 {
		fmt.Fprintf(w,
			"<span class=line> %6d</span> <span class=nop>  %10s %10s %s </span>\n",
			fn.info.lineno,
			valueOrDot(fn.flat, rpt), valueOrDot(fn.cum, rpt),
			template.HTMLEscapeString(fn.info.name))
		return
	}

	fmt.Fprintf(w,
		"<span class=line> %6d</span> <span class=deadsrc>  %10s %10s %s </span>",
		fn.info.lineno,
		valueOrDot(fn.flat, rpt), valueOrDot(fn.cum, rpt),
		template.HTMLEscapeString(fn.info.name))
	fmt.Fprint(w, "<span class=asm>")
	for _, an := range assembly {
		var fileline string
		class := "disasmloc"
		if an.info.file != "" {
			fileline = fmt.Sprintf("%s:%d", template.HTMLEscapeString(an.info.file), an.info.lineno)
			if an.info.lineno != fn.info.lineno {
				class = "unimportant"
			}
		}
		fmt.Fprintf(w, " %8s %10s %10s %8x: %-48s <span class=%s>%s</span>\n", "",
			valueOrDot(an.flat, rpt), valueOrDot(an.cum, rpt),
			an.info.address,
			template.HTMLEscapeString(an.info.name),
			class,
			template.HTMLEscapeString(fileline))
	}
	fmt.Fprintln(w, "</span>")
}
开发者ID:gaoxiaojun,项目名称:cc,代码行数:35,代码来源:source.go

示例15: Render

// Render renders the HTML element into its string representation.
// It also surfaces all initFuncs to the top and returns them.
func (s HTML) Render() (string, []func()) {
	var result string
	var initFuncs []func()
	if s.tag != "" {
		result = "<" + s.tag
		for _, v := range s.props {
			result += fmt.Sprintf(" %s=%q", v[0], template.HTMLEscapeString(v[1]))
		}
		var styles string
		for _, v := range s.styles {
			styles += fmt.Sprintf("%s:%s;", v[0], template.HTMLEscapeString(v[1]))
		}
		if styles != "" {
			result += fmt.Sprintf(" style=%q", styles)
		}
		if s.body == "" && len(s.elems) == 0 {
			result += "/"
		}
		result += ">"
	}
	for _, v := range s.elems {
		str, ifs := v.Render()
		result += str
		initFuncs = append(initFuncs, ifs...)
	}
	initFuncs = append(initFuncs, s.initFuncs...)
	result += template.HTMLEscapeString(s.body)
	if s.tag != "" && !(s.body == "" && len(s.elems) == 0) {
		result += "</" + s.tag + ">"
	}
	return result, initFuncs
}
开发者ID:gmlewis,项目名称:go-frp,代码行数:34,代码来源:html.go


注:本文中的html/template.HTMLEscapeString函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。