From 337254333f62e4f7ff18c1c1548c0b866de724c6 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Sat, 20 Aug 2011 12:39:38 -0700 Subject: [PATCH] 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 --- src/cmd/godoc/godoc.go | 14 +++++++++++++- src/cmd/godoc/main.go | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/cmd/godoc/godoc.go b/src/cmd/godoc/godoc.go index b8a83940438..3d29db5199d 100644 --- a/src/cmd/godoc/godoc.go +++ b/src/cmd/godoc/godoc.go @@ -540,7 +540,19 @@ func readTemplate(name string) *template.Template { 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 ( diff --git a/src/cmd/godoc/main.go b/src/cmd/godoc/main.go index 89b12b9acbb..48bfa2477e9 100644 --- a/src/cmd/godoc/main.go +++ b/src/cmd/godoc/main.go @@ -250,8 +250,8 @@ func main() { fsHttp = NewHttpZipFS(rc, *goroot) } - initHandlers() readTemplates() + initHandlers() if *httpAddr != "" { // HTTP server mode.