本文整理汇总了Golang中template.Template.Execute方法的典型用法代码示例。如果您正苦于以下问题:Golang Template.Execute方法的具体用法?Golang Template.Execute怎么用?Golang Template.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类template.Template
的用法示例。
在下文中一共展示了Template.Execute方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: generateRouter
func generateRouter() {
//mkdir for the initiator
err := os.MkdirAll(*TargetFullPath+"/router/", 0755)
if err != nil {
fmt.Println("Unable to create directory, ", err.String())
}
f, err := os.Create(*TargetFullPath + "/router/" + "router.go")
if err != nil {
fmt.Println(err.String())
}
defer f.Close()
var templ *template.Template
templ = template.New(nil)
templ.SetDelims("<%", "%>")
err = templ.Parse(routerTemplate)
if err != nil {
fmt.Println(err.String())
}
err = templ.Execute(f, map[string]interface{}{
"PackageName": *PackageName,
"ServiceName": *ServiceName,
})
if err != nil {
fmt.Println(err.String())
}
}
示例2: applyTemplate
func applyTemplate(t *template.Template, name string, data interface{}) []byte {
var buf bytes.Buffer
if err := t.Execute(data, &buf); err != nil {
log.Printf("%s.Execute: %s", name, err)
}
return buf.Bytes()
}
示例3: renderTemplateFromFile
/* Apply an HTML template and render.
*
* @param templ an HTML template
* @tempData usually a struct passed to the template
* @w the response writer that should render the template
*/
func renderTemplateFromFile(context appengine.Context, templ *template.Template, tempData interface{}, w http.ResponseWriter) {
err := templ.Execute(w, tempData)
if err != nil {
serveError(context, w, http.StatusInternalServerError, err) // 500
}
return
}
示例4: template_exec
func template_exec(tpl *template.Template, request uintptr, k_output uint64, k_input uint64) (err string) {
wr, ok2 := f.Hget(request, k_output).(io.Writer)
data := f.Hget(request, k_input)
if !ok2 {
return fmt.Sprintf("templateExecute_handler input data invalid: tpl {%v}; output {%v, %v}; data {%v}",
tpl, wr, ok2, data)
}
if e := tpl.Execute(data, wr); e != nil {
return fmt.Sprintf("templateExecute_handler template execution error: %v", e)
}
return ""
}
示例5: render
func render(tmplString string, context interface{}) (string, os.Error) {
var tmpl *template.Template
var err os.Error
if tmpl, err = template.Parse(tmplString, nil); err != nil {
return "", err
}
var buf bytes.Buffer
tmpl.Execute(context, &buf)
return buf.String(), nil
}
示例6: main
func main() {
prepareCache()
queryString := parseQueryString(os.Getenv("QUERY_STRING"))
fmap := template.FormatterMap{"html": template.HTMLFormatter}
opts := map[string](interface{}){}
os.Stdout.WriteString("Content-type: text/html\n\n")
conn := db.PrepareConnection(Cache["db"])
hdr, _ := template.ParseFile(Cache["tpl:headr"], fmap)
tmpl := new(template.Template)
if queryString["forum"] != "" {
tmpl, _ = template.ParseFile(Cache["tpl:forum"], fmap)
opts["forum"] = db.Get(conn, db.Forum{}, queryString["forum"])
} else {
tmpl, _ = template.ParseFile(Cache["tpl:index"], fmap)
}
_ = strconv.Itoa
c, _ := conf.ReadConfigFile(path.Join(Cache["wd"], "flow.config"))
opts["version"] = Version
opts["title"], _ = c.GetString("default", "boardName")
defer conn.Close()
if !db.TablesExist(conn) {
db.SetupForum(conn)
}
stmt, _ := conn.Prepare("SELECT id, name, desc FROM forum;")
db.HandleError(stmt.Exec())
forums := []db.Forum{}
if stmt.Next() {
var f db.Forum
db.HandleError(stmt.Scan(&f.Id, &f.Name, &f.Desc))
forums = append(forums, f)
}
opts["forums"] = forums
opts["cwd"] = Cache["cwdir"]
hdr.Execute(opts, os.Stdout)
tmpl.Execute(opts, os.Stdout)
}
示例7: funcToHTML
func funcToHTML(fset *token.FileSet, t *doce.Func, tpl *template.Template) string {
b := bytes.NewBuffer(make([]byte, 0, 128))
recvnostar := t.Recv
if recvnostar != "" && recvnostar[0] == '*' {
recvnostar = recvnostar[1:]
}
var data = map[string]string{
"name": t.Name,
"code": codeToString(fset, t.Decl),
"comment": commentToHTML(t.Doc),
"recv": t.Recv,
"recvnostar": recvnostar,
}
tpl.Execute(b, data)
return b.String()
}
示例8: printFiles
/*
* Prints out the information given to you by ls.Ls depending on the flags
* given
*
*/
func printFiles(numArgs int, data [][]ls.FileData, path string, n *bool, temp *template.Template) {
for pos, dir := range data {
if pos != 0 {
path += "/"
path += dir[0].Name
fmt.Printf("\n%s:\n", path)
} else if numArgs > 1 {
fmt.Printf("%s:\n", path)
}
if *n {
fmt.Printf("total %d\n", totalBlocks(dir))
}
for pos1, file := range dir {
if pos1 != 0 {
if *n {
temp.Execute(os.Stdout, file)
} else {
fmt.Println(file.Name)
}
}
}
}
fmt.Println()
}
示例9: run
func run(t *template.Template, a interface{}, out io.Writer) {
if err := t.Execute(out, a); err != nil {
panic(err)
}
}
示例10: QR
func QR(c *http.Conn, req *http.Request, templ *template.Template) {
templ.Execute(req.FormValue("s"), c)
}