本文整理汇总了Golang中html/template.Template类的典型用法代码示例。如果您正苦于以下问题:Golang Template类的具体用法?Golang Template怎么用?Golang Template使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Template类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: BulkHandler
func BulkHandler(Layout *template.Template, Exits *Exits) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
ip := r.URL.Query().Get("ip")
if net.ParseIP(ip) == nil {
if err := Layout.ExecuteTemplate(w, "bulk.html", nil); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
return
}
port_str := r.URL.Query().Get("port")
port, err := strconv.Atoi(port_str)
port_str = "&port=" + port_str
if err != nil {
port = 80
port_str = ""
}
str := fmt.Sprintf("# This is a list of all Tor exit nodes that can contact %s on Port %d #\n", ip, port)
str += fmt.Sprintf("# You can update this list by visiting https://check.torproject.org/cgi-bin/TorBulkExitList.py?ip=%s%s #\n", ip, port_str)
str += fmt.Sprintf("# This file was generated on %v #\n", Exits.UpdateTime.UTC().Format(time.UnixDate))
str += Exits.Dump(ip, port)
fmt.Fprintf(w, str)
}
}
开发者ID:Ryman,项目名称:check,代码行数:29,代码来源:handlers.go
示例2: renderHTML
func renderHTML(w http.ResponseWriter, r *http.Request, task types.EremeticTask, taskID string) {
var err error
var tpl *template.Template
data := make(map[string]interface{})
funcMap := template.FuncMap{
"ToLower": strings.ToLower,
}
if task == (types.EremeticTask{}) {
tpl, err = template.ParseFiles("templates/error_404.html")
data["TaskID"] = taskID
} else {
tpl, err = template.New("task.html").Funcs(funcMap).ParseFiles("templates/task.html")
data = makeMap(task)
}
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
log.Error(err.Error())
return
}
err = tpl.Execute(w, data)
}
开发者ID:mommel,项目名称:eremetic,代码行数:25,代码来源:handler.go
示例3: notFound
func notFound(ci inject.CopyInject, templates *template.Template, w http.ResponseWriter) error {
err := ci.ServeTemplate(http.StatusNotFound, w, templates.Lookup("404.html"), nil)
if err != nil {
return err
}
return nil
}
开发者ID:rawbite,项目名称:devd,代码行数:7,代码来源:fileserver.go
示例4: loadTemplate
func (v *Views) loadTemplate(name, content string, t *template.Template) {
log.Println("loaded template", name)
_, err := t.New(name).Parse(content)
if err != nil {
log.Panic(err)
}
}
开发者ID:timtadh,项目名称:cc-survey,代码行数:7,代码来源:views.go
示例5: getTemplateInstance
func (v *View) getTemplateInstance(tpl []string) (*template.Template, error) {
key := strings.Join(tpl, "-")
// if IsCache, get cached template if exist
if v.IsCache {
if v.templateCache[key] != nil {
return v.templateCache[key], nil
}
}
var (
t *template.Template
e error
file []string = make([]string, len(tpl))
)
for i, tp := range tpl {
file[i] = path.Join(v.Dir, tp)
}
t = template.New(path.Base(tpl[0]))
t.Funcs(v.FuncMap)
t, e = t.ParseFiles(file...)
if e != nil {
return nil, e
}
if v.IsCache {
v.templateCache[key] = t
}
return t, nil
}
开发者ID:Lao-liu,项目名称:GoInk,代码行数:28,代码来源:view.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng