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


Golang template.HTMLEscapeString函数代码示例

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


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

示例1: Radios

func (w *RadioWidget) Radios(attrs []string, checkedValue string) []template.HTML {
	id, _ := w.Attrs().Get("id")
	radios := make([]template.HTML, 0, len(w.choices))
	for i, choice := range w.choices {
		wAttrs := w.Attrs().Clone()
		wAttrs.Set("id", fmt.Sprintf("%v_%v", id, i))
		wAttrs.FromSlice(attrs)

		value := tTemplate.HTMLEscapeString(choice[0])
		label := tTemplate.HTMLEscapeString(choice[1])

		checked := ""
		if value == checkedValue {
			checked = ` checked="checked"`
		}

		radio := fmt.Sprintf(
			`<input%v value="%v"%v /> %v`,
			wAttrs.String(),
			value,
			checked,
			label)
		radios = append(radios, template.HTML(radio))
	}
	return radios
}
开发者ID:RangelReale,项目名称:gforms,代码行数:26,代码来源:widgets.go

示例2: login

func login(w http.ResponseWriter, r *http.Request) {
	fmt.Println("method:", r.Method) //get request 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 {
		// log in request
		r.ParseForm()
		token := r.Form.Get("token")
		if token != "" {
			fmt.Println("Token: ", 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"))) // print in server side
		fmt.Println("password:", template.HTMLEscapeString(r.Form.Get("password")))
		template.HTMLEscape(w, []byte(r.Form.Get("username"))) // respond to client
	}
}
开发者ID:espang,项目名称:examples,代码行数:26,代码来源:server.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("login.gtpl")
		t.Execute(w, token)
	} else {
		//请求的是登陆数据,那么执行登陆的逻辑判断
		r.ParseForm()
		token := r.Form.Get("token")
		fmt.Println(token)
		if token != "" {

			fmt.Println("***************************")
			//验证token的合法性
		} else {
			fmt.Println("============================")
			//不存在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:pokerG,项目名称:GoBeginner,代码行数:29,代码来源:upload.go

示例4: Format

func (a *FragmentFormatterEx) Format(f *highlight.Fragment, orderedTermLocations highlight.TermLocations) string {
	rv := ""
	curr := f.Start
	for _, termLocation := range orderedTermLocations {
		if termLocation == nil {
			continue
		}
		if termLocation.Start < curr {
			continue
		}
		if termLocation.End > f.End {
			break
		}
		// add the stuff before this location
		rv += tt.HTMLEscapeString(string(f.Orig[curr:termLocation.Start]))
		// add the color
		rv += a.before
		// add the term itself
		rv += tt.HTMLEscapeString(string(f.Orig[termLocation.Start:termLocation.End]))
		// reset the color
		rv += a.after
		// update current
		curr = termLocation.End
	}
	// add any remaining text after the last token
	rv += tt.HTMLEscapeString(string(f.Orig[curr:f.End]))

	return rv
}
开发者ID:oblank,项目名称:knowledgedb,代码行数:29,代码来源:fragmentformatterex.go

示例5: handleSign

func handleSign(w http.ResponseWriter, r *http.Request) {
	if r.Method != "POST" {
		serve404(w)
		return
	}
	c := appengine.NewContext(r)
	u := user.Current(c)
	userName := ""
	if u != nil { //a google user
		userName = u.String()
	} else { //not a google user
		//is it a local user?
		cookie, err := r.Cookie("email")
		if err == nil {
			userName = cookie.Value
		} else { //no logged in yet

			badRequest(w, "Only login user can post messages.")
			return
		}
	}
	if err := r.ParseForm(); err != nil {
		serveError(c, w, err)
		return
	}
	tagsString := r.FormValue("tags")
	m := &Message{
		ID:      0,
		Title:   template.HTMLEscapeString(r.FormValue("title")),
		Author:  template.HTMLEscapeString(r.FormValue("author")),
		Content: []byte(template.HTMLEscapeString(r.FormValue("content"))),
		Tags:    strings.Split(template.HTMLEscapeString(tagsString), ","),
		Date:    time.Now(),
		Views:   0,
		Good:    0,
		Bad:     0,
	}
	if badTitle(m.Title) || badAuthor(m.Author) || badContent(string(m.Content)) || badTag(tagsString) {
		badRequest(w, "Input too long")
		return
	}

	processMsgContent(m)
	//TODO: build References and Referedby list
	if u := user.Current(c); u != nil {
		m.Author = userName
		//TODO: hook this message under user's msglist
	}
	k, err := datastore.Put(c, datastore.NewIncompleteKey(c, "aMessage", nil), m)
	if err != nil {
		serveError(c, w, err)
		return
	}
	putMsgTags(r, k.IntID(), m.Tags)
	setCount(w, r)
	http.Redirect(w, r, "/", http.StatusFound)
}
开发者ID:DeanSinaean,项目名称:csnuts,代码行数:57,代码来源:handleSign.go

示例6: Compute

func Compute(uc *understand.Circuit) *Circuit {
	c := &Circuit{Name: uc.Name()}

	// Peers
	var z float64 // Total weight
	var i int
	inv := make(map[*understand.Peer]int)
	for _, p := range uc.Peer {
		inv[p] = i
		// weight := float64(len(p.Valve))
		z += 1
		c.Peer = append(c.Peer,
			&Peer{
				ID:     fmt.Sprintf("peer-%s", p.Name),
				Name:   template.HTMLEscapeString(fmt.Sprintf("%v", p.Name)),
				Design: template.HTMLEscapeString(fmt.Sprintf("%v", p.Design)),
				Weight: 1, //weight,
			},
		)
		i++
	}
	var u float64
	const MaxRadius = 0.9
	for _, p := range c.Peer {
		p.Angle = 2 * math.Pi * (u + p.Weight/2) / z
		p.Anchor = CirclePointOfAngle(p.Angle)
		p.Radius = MaxRadius * p.Weight / z
		u += p.Weight
	}

	// Matchings
	for _, p := range uc.Peer { // From
		pp := c.Peer[inv[p]]
		for _, v := range p.Valve { // To
			qq := c.Peer[inv[v.Matching.Of]]
			x := pp.Anchor
			y := qq.Anchor
			c.Match = append(c.Match,
				&Match{
					ID:          fmt.Sprintf("match-%s-%s", pp.Name, v.Name),
					FromAnchor:  x,
					ToAnchor:    y,
					FromTangent: Scalar(0.5, x),
					ToTangent:   Scalar(0.5, y),
					Valve:       v.Name,
				},
			)
		}
	}
	return c
}
开发者ID:dasmithii,项目名称:escher,代码行数:51,代码来源:draw.go

示例7: directiveInsertWordBreaks

func directiveInsertWordBreaks(value data.Value, args []data.Value) data.Value {
	var (
		input    = template.HTMLEscapeString(value.String())
		maxChars = int(args[0].(data.Int))
		chars    = 0
		output   *bytes.Buffer // create the buffer lazily
	)
	for i, ch := range input {
		switch {
		case ch == ' ':
			chars = 0
		case chars >= maxChars:
			if output == nil {
				output = bytes.NewBufferString(input[:i])
			}
			output.WriteString("<wbr>")
			chars = 1
		default:
			chars++
		}
		if output != nil {
			output.WriteRune(ch)
		}
	}
	if output == nil {
		return value
	}
	return data.String(output.String())
}
开发者ID:voidException,项目名称:soy,代码行数:29,代码来源:directives.go

示例8: Options

func (w *SelectWidget) Options(selValues ...string) []string {
	options := make([]string, 0, len(w.choices))
	for _, choice := range w.choices {
		value := tTemplate.HTMLEscapeString(choice[0])
		label := tTemplate.HTMLEscapeString(choice[1])
		attrs := ""
		for _, selValue := range selValues {
			if value == selValue {
				attrs = ` selected="selected"`
			}
		}
		option := fmt.Sprintf(`<option value="%v"%v>%v</option>`, value, attrs, label)
		options = append(options, option)
	}
	return options
}
开发者ID:RangelReale,项目名称:gforms,代码行数:16,代码来源:widgets.go

示例9: parse_input

func (disp_handler DispHandler) parse_input(r *http.Request) (locate_id uint32, err error) {

	//先解析获取数据
	err = r.ParseForm()

	if err != nil {
		return
	}

	locate_id = 0
	var tmp uint64 = 0

	str_locate_id, ok := r.Form["locate_id"]

	if ok == false {
		err = ErrorInputParameter
		return
	} else {
		tmp, err = strconv.ParseUint(template.HTMLEscapeString(str_locate_id[0]), 10, 32)
		if err != nil || tmp == 0 {
			err = ErrorInputParameter
			return
		} else {
			locate_id = uint32(tmp)
		}
	}

	err = nil
	return
}
开发者ID:chouqiu,项目名称:weishenghuo,代码行数:30,代码来源:disp.go

示例10: code

func code(file string, arg []interface{}) (string, error) {
	text := contents(file)
	var command string
	switch len(arg) {
	case 0:
		// whole file.
		command = fmt.Sprintf("code %q", file)
	case 1:
		// one line, specified by line or regexp.
		command = fmt.Sprintf("code %q %s", file, format(arg[0]))
		text = oneLine(file, text, arg[0])
	case 2:
		// multiple lines, specified by line or regexp.
		command = fmt.Sprintf("code %q %s %s", file, format(arg[0]), format(arg[1]))
		text = multipleLines(file, text, arg[0], arg[1])
	default:
		return "", fmt.Errorf("incorrect code invocation: code %q %v", file, arg)
	}
	// Replace tabs by spaces, which work better in HTML.
	text = strings.Replace(text, "\t", "    ", -1)
	// Escape the program text for HTML.
	if *html {
		text = template.HTMLEscapeString(text)
	}
	// Include the command as a comment.
	if *html {
		text = fmt.Sprintf("<!--{{%s}}\n-->%s", command, text)
	} else {
		text = fmt.Sprintf("// %s\n%s", command, text)
	}
	return text, nil
}
开发者ID:khasteh,项目名称:chat,代码行数:32,代码来源:makeslide.go

示例11: exampleIdFn

func exampleIdFn(v interface{}, example *doc.Example) string {
	buf := make([]byte, 0, 64)
	buf = append(buf, "_example"...)

	switch v := v.(type) {
	case *doc.Type:
		buf = append(buf, '_')
		buf = append(buf, v.Name...)
	case *doc.Func:
		buf = append(buf, '_')
		if v.Recv != "" {
			if v.Recv[0] == '*' {
				buf = append(buf, v.Recv[1:]...)
			} else {
				buf = append(buf, v.Recv...)
			}
			buf = append(buf, '_')
		}
		buf = append(buf, v.Name...)
	}
	if example.Name != "" {
		buf = append(buf, '-')
		buf = append(buf, example.Name...)
	}
	return template.HTMLEscapeString(string(buf))
}
开发者ID:jeffallen,项目名称:gopkgdoc,代码行数:26,代码来源:template.go

示例12: breadcrumbsFn

func breadcrumbsFn(pdoc *doc.Package) string {
	if !strings.HasPrefix(pdoc.ImportPath, pdoc.ProjectRoot) {
		return ""
	}
	var buf bytes.Buffer
	i := 0
	j := len(pdoc.ProjectRoot)
	if j == 0 {
		buf.WriteString("<a href=\"/-/go\" title=\"Standard Packages\">☆</a> ")
		j = strings.IndexRune(pdoc.ImportPath, '/')
		if j < 0 {
			j = len(pdoc.ImportPath)
		}
	}
	for {
		buf.WriteString(`<a href="/`)
		buf.WriteString(urlFn(pdoc.ImportPath[:j]))
		buf.WriteString(`">`)
		buf.WriteString(template.HTMLEscapeString(pdoc.ImportPath[i:j]))
		buf.WriteString("</a>")
		i = j + 1
		if i >= len(pdoc.ImportPath) {
			break
		}
		buf.WriteByte('/')
		j = strings.IndexRune(pdoc.ImportPath[i:], '/')
		if j < 0 {
			j = len(pdoc.ImportPath)
		} else {
			j += i
		}
	}
	return buf.String()
}
开发者ID:jeffallen,项目名称:gopkgdoc,代码行数:34,代码来源:template.go

示例13: code

func code(file string, arg ...interface{}) (string, error) {
	text := contents(file)
	var command string
	switch len(arg) {
	case 0:
		// text is already whole file.
		command = fmt.Sprintf("code %q", file)
	case 1:
		command = fmt.Sprintf("code %q %s", file, format(arg[0]))
		text = oneLine(file, text, arg[0])
	case 2:
		command = fmt.Sprintf("code %q %s %s", file, format(arg[0]), format(arg[1]))
		text = multipleLines(file, text, arg[0], arg[1])
	default:
		return "", fmt.Errorf("incorrect code invocation: code %q %q", file, arg)
	}
	// Trim spaces from output.
	text = strings.Trim(text, "\n")
	// Replace tabs by spaces, which work better in HTML.
	text = strings.Replace(text, "\t", "    ", -1)
	// Escape the program text for HTML.
	text = template.HTMLEscapeString(text)
	// Include the command as a comment.
	text = fmt.Sprintf("<pre><!--{{%s}}\n-->%s</pre>", command, text)
	return text, nil
}
开发者ID:joninvski,项目名称:go,代码行数:26,代码来源:tmpltohtml.go

示例14: TestEscapge

func TestEscapge() {
	str := template.HTMLEscapeString("<br>hello</br>")
	fmt.Println(str)

	jsStr := template.JSEscapeString("<script>alert('123')</script>")
	fmt.Println(jsStr)
}
开发者ID:yunkaiyueming,项目名称:go_code,代码行数:7,代码来源:template.go

示例15: importPathFn

// importPathFn formats an import with zero width space characters to allow for breaks.
func importPathFn(path string) string {
	path = template.HTMLEscapeString(path)
	if len(path) > 45 {
		// Allow long import paths to break following "/"
		path = strings.Replace(path, "/", "/&#8203;", -1)
	}
	return path
}
开发者ID:jeffallen,项目名称:gopkgdoc,代码行数:9,代码来源:template.go


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