1
0
mirror of https://github.com/golang/go synced 2024-11-22 00:24:41 -07:00

godoc: minor fixes

- templates should be read before any handlers are started
- for app engine use, must use underlying file system to read templates

R=r
CC=golang-dev
https://golang.org/cl/4928042
This commit is contained in:
Robert Griesemer 2011-08-20 12:39:38 -07:00
parent 72ddc87681
commit 337254333f
2 changed files with 14 additions and 2 deletions

View File

@ -540,7 +540,19 @@ func readTemplate(name string) *template.Template {
path = defaultpath path = defaultpath
} }
} }
return template.Must(template.New(name).Funcs(fmap).ParseFile(path))
// use underlying file system fs to read the template file
// (cannot use template ParseFile functions directly)
data, err := fs.ReadFile(path)
if err != nil {
log.Fatal("readTemplate: ", err)
}
// be explicit with errors (for app engine use)
t, err := template.New(name).Funcs(fmap).Parse(string(data))
if err != nil {
log.Fatal("readTemplate: ", err)
}
return t
} }
var ( var (

View File

@ -250,8 +250,8 @@ func main() {
fsHttp = NewHttpZipFS(rc, *goroot) fsHttp = NewHttpZipFS(rc, *goroot)
} }
initHandlers()
readTemplates() readTemplates()
initHandlers()
if *httpAddr != "" { if *httpAddr != "" {
// HTTP server mode. // HTTP server mode.