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


Golang template.MustParse函数代码示例

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


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

示例1: main

func main() {
	// Pull in command line options or defaults if none given
	flag.Parse()

	f, err := os.OpenFile(*skylib.LogFileName, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
	if err == nil {
		defer f.Close()
		log.SetOutput(f)
	}

	skylib.Setup(sName)

	homeTmpl = template.MustParse(homeTemplate, nil)
	respTmpl = template.MustParse(responseTemplate, nil)

	rpc.HandleHTTP()

	portString := fmt.Sprintf("%s:%d", *skylib.BindIP, *skylib.Port)

	stack := new(mango.Stack)
	stack.Address = portString

	routes := make(map[string]mango.App)
	routes["/"] = homeHandler
	routes["/new"] = submitHandler
	stack.Middleware(mango.Routing(routes))
	stack.Run(nil)
}
开发者ID:paulbellamy,项目名称:skynet,代码行数:28,代码来源:mangoInitiator.go

示例2: main

func main() {

	var err os.Error

	// Pull in command line options or defaults if none given
	flag.Parse()

	f, err := os.OpenFile(*skylib.LogFileName, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
	if err == nil {
		defer f.Close()
		log.SetOutput(f)
	}

	skylib.Setup(sName)

	homeTmpl = template.MustParse(homeTemplate, nil)
	respTmpl = template.MustParse(responseTemplate, nil)

	http.HandleFunc("/", homeHandler)
	http.HandleFunc("/new", submitHandler)

	rpc.HandleHTTP()

	portString := fmt.Sprintf("%s:%d", *skylib.BindIP, *skylib.Port)

	err = http.ListenAndServe(portString, nil)
	if err != nil {
		log.Fatal("ListenAndServe: ", err.String())
	}
}
开发者ID:repos-go,项目名称:skynet,代码行数:30,代码来源:web.go

示例3: ShowErrors

func ShowErrors(templateString string) Middleware {
	if templateString == "" {
		templateString = `
      <html>
      <body>
        <p>
          {Error|html}
        </p>
      </body>
      </html>
    `
	}

	errorTemplate := template.MustParse(templateString, nil)

	return func(env Env, app App) (status Status, headers Headers, body Body) {
		defer func() {
			if err := recover(); err != nil {
				buffer := bytes.NewBufferString("")
				errorTemplate.Execute(buffer, struct{ Error string }{err.(string)})
				status = 500
				headers = Headers{}
				body = Body(buffer.String())
			}
		}()

		return app(env)
	}
}
开发者ID:qrush,项目名称:higo,代码行数:29,代码来源:show_errors.go

示例4: parseChunk

func parseChunk(lines []string, lesson *Lesson) *Chunk {
	ret := &Chunk{Title: lines[0], ToC: make([]*ChunkSlide, 0, 10), Lesson: lesson}
	lines = lines[1:]

	ret.DescHTML, lines = parseText(lines, false, nil)
	ret.SRSItems = getSRSItems(lines)

	cont := ""
	partNum := 0
	for len(lines) != 0 && (len(lines) != 1 || lines[0] != "") {
		if lines[0][0:7] != "\\slide:" {
			log.Panicf("Error : expected '\\slide:' directive in chunk file.")
		}
		slideTitle := lines[0][7:]
		lines = lines[1:]
		slideText, nl := parseText(lines, true, ret)
		lines = nl

		partNum++
		cont += fmt.Sprintf(`
<div class="slide" id="part%v" name="part%v">
	<h1>%v</h1>
	%v
</div>
`, partNum, partNum, slideTitle, slideText)
		ret.ToC = append(ret.ToC, &ChunkSlide{partNum, slideTitle})
	}
	// fmt.Printf(cont)		//DEBUG
	ret.Contents = template.MustParse(cont, nil)

	return ret
}
开发者ID:Alexis211,项目名称:ajstk,代码行数:32,代码来源:parser.go

示例5: init

func init() {
	frontPage = template.New(nil)
	frontPage.SetDelims("«", "»")
	if err := frontPage.Parse(frontPageText); err != nil {
		panic(err)
	}
	output = template.MustParse(outputText, nil)
}
开发者ID:ssrl,项目名称:go,代码行数:8,代码来源:goplay.go

示例6: loadTemplate

func loadTemplate(path string) (t *template.Template, err os.Error) {
	if buf, readErr := io.ReadFile("templates/" + path); readErr == nil {
		t = template.MustParse(string(buf), template.FormatterMap{
			"html": template.HTMLFormatter
		});
	} else {
		err = readErr
	}
	return;
}
开发者ID:tung,项目名称:goblog,代码行数:10,代码来源:views.go

示例7: main

func main() {
	// Pull in command line options or defaults if none given
	flag.Parse()

	skylib.NewAgent().Start()

	homeTmpl = template.MustParse(homeTemplate, nil)
	respTmpl = template.MustParse(responseTemplate, nil)

	portString := fmt.Sprintf("%s:%d", *skylib.BindIP, *skylib.Port)

	stack := new(mango.Stack)
	stack.Address = portString

	routes := make(map[string]mango.App)
	routes["/"] = homeHandler
	routes["/new"] = submitHandler
	stack.Middleware(mango.Routing(routes))
	stack.Run(nil)
}
开发者ID:andradeandrey,项目名称:skynet,代码行数:20,代码来源:mangoInitiator.go

示例8: conventionCard

func conventionCard(c http.ResponseWriter, p Settings) {
	fmt.Fprintln(c, `<script type="text/javascript">
function submitform() {
    document.forms["catchall"].submit();
}
</script>
`)
	e := template.MustParse(cctemplate, htmlcardformatter).Execute(p.Card(), c)
	if e != nil {
		fmt.Println("Template error:", e)
	}
}
开发者ID:droundy,项目名称:abridge,代码行数:12,代码来源:cardtemplate.go

示例9: main

func main() {

	var err os.Error

	// Pull in command line options or defaults if none given
	flag.Parse()

	skylib.NewAgent().Start()

	homeTmpl = template.MustParse(homeTemplate, nil)
	respTmpl = template.MustParse(responseTemplate, nil)

	http.HandleFunc("/", homeHandler)
	http.HandleFunc("/new", submitHandler)

	portString := fmt.Sprintf("%s:%d", *skylib.BindIP, *skylib.Port)

	err = http.ListenAndServe(portString, nil)
	if err != nil {
		log.Fatal("ListenAndServe: ", err.String())
	}
}
开发者ID:andradeandrey,项目名称:skynet,代码行数:22,代码来源:web.go

示例10: getTemplate

// getTemplate returns a template at a given filepath.
func getTemplate(filepath string) *template.Template {
	if templates[filepath] == nil {
		file, err := os.Open(template_dir+filepath, os.O_RDONLY, 0666)
		if err != nil {
			log.Exit("not exist: %s", filepath)
		}
		reader := bufio.NewReader(file)
		body, _ := reader.ReadString('~')
		tmpl := template.MustParse(body, nil)
		templates[filepath] = tmpl
	}
	return templates[filepath]
}
开发者ID:Kazuya-Muramatsu,项目名称:Go-Go,代码行数:14,代码来源:http_server.go

示例11: writePackagePage

func writePackagePage(pkgname string) {
	// TODO: I/O error checks
	pkgfilename := strings.Replace(pkgname, "/", "_", -1)
	dest := path.Join(*optOutDir, pkgfilename+".html")

	f, err := os.Create(dest)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	defer f.Close()
	bf := bufio.NewWriter(f)

	var packageTemplate = template.MustParse(packageTemplateStr, nil)

	tplparams := map[string]string{
		"pkgname":  pkgname,
		"datafile": "gortfm-" + pkgfilename + "-data.js",
	}
	packageTemplate.Execute(bf, tplparams)
	bf.Flush()
}
开发者ID:nsf,项目名称:gortfm,代码行数:22,代码来源:gortfm.go

示例12: serveError

func serveError(req *web.Request, status int, reason os.Error, header web.Header) {
	header.Set(web.HeaderContentType, "text/plain; charset=utf-8")
	w := req.Responder.Respond(status, header)
	io.WriteString(w, web.StatusText(status))
	if reason != nil {
		io.WriteString(w, "\n")
		io.WriteString(w, reason.String())
	}
}

var mainPage = template.MustParse(`<html><body>
{.repeated section gg}
{.section Author}<b>{@|html}</b>{.or}An anonymous person{.end}
wrote <blockquote>{Content|html}</blockquote>
{.end}
<form action="/sign" method="POST">
<div><input type="hidden" name="xsrf" value="{xsrf}"> <textarea name="content" rows="3" cols="60"></textarea></div>
<div><input type="submit" value="Sign Guestbook"></div>
</form></body></html>`,
	nil)

func handleMainPage(r *web.Request) {
	c := gae.Context(r)
	q := datastore.NewQuery("Greeting").Order("-Date").Limit(10)
	var gg []*Greeting
	_, err := q.GetAll(c, &gg)
	if err != nil {
		r.Error(web.StatusInternalServerError, err)
		return
	}
	w := r.Respond(200, "Content-Type", "text/html")
开发者ID:adamsxu,项目名称:twister,代码行数:31,代码来源:guestbook.go

示例13:

var makefileTemplate = template.MustParse(`
include $(GOROOT)/src/Make.inc

TARG={Targ}
TARGDIR={TargDir}

{.section GoFiles}
GOFILES=\
{.repeated section @}
	{@}\
{.end}

{.end}
{.section OFiles}
OFILES=\
{.repeated section @}
	{@}\
{.end}

{.end}
{.section CgoFiles}
CGOFILES=\
{.repeated section @}
	{@}\
{.end}

{.end}
{.section CgoOFiles}
CGO_OFILES=\
{.repeated section @}
	{@}\
{.end}

{.end}
GCIMPORTS={.repeated section Imports}-I "{@}" {.end}
LDIMPORTS={.repeated section Imports}-L "{@}" {.end}

include $(GOROOT)/src/Make.{Type}
`,
	nil)
开发者ID:ssrl,项目名称:go,代码行数:40,代码来源:make.go

示例14:

<html>
<body>
<h1>Who is on it?</h1>
<h2>Current Emails</h2>
<ul>
{.repeated section @}
  <li><a href="/show?sender={Sender}&date={RecieptDate}">{Sender} - {Subject} - {RecieptDate}</a></li>
{.or}
Nothing to do. Good job.
{.end}
</ul>
</body>
</html>
`

var rootTemplate = template.MustParse(root_template, nil)

const show_template = `
<html>
<body>
{.repeated section @}
<h1>{Subject|html}</h1>
<h2>{Sender}</h2>
<h3>Status</h3>
<p>Received: {RecieptDate}</p>
<p>Owner: {.section Owner}{Owner}</p>
<p>Accepted On: {OwnerDate}{.or}Nobody{.end}</p>
{.section ClosedDate}
<p>Closed On: {ClosedDate}</p>
{.end}
<h3>Message Content</h3>
开发者ID:cyberkni,项目名称:whosonit,代码行数:31,代码来源:templates.go

示例15: main

	oauthClient.Credentials.Secret = m["ClientSecret"].(string)
}

func main() {
	flag.Parse()
	readSettings()
	h := web.FormHandler(10000, true, web.NewRouter().
		Register("/", "GET", home).
		Register("/login", "GET", login).
		Register("/callback", "GET", authCallback))

	server.Run(":8080", h)
}

var fmap = template.FormatterMap{"": template.HTMLFormatter}
var homeLoggedOutTempl = template.MustParse(homeLoggedOutStr, fmap)

const homeLoggedOutStr = `
<html>
<head>
</head>
<body>
<a href="/login"><img src="http://a0.twimg.com/images/dev/buttons/sign-in-with-twitter-d.png"></a>
</body>
</html>`

var homeTempl = template.MustParse(homeStr, fmap)

const homeStr = `
<html>
<head>
开发者ID:rene-dev,项目名称:twister,代码行数:31,代码来源:main.go


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