webtry: Simplify template construction.
text/template and html/template both have a helper function called
"Must" that according to the docs in http://golang.org/pkg/text/template/#Must
and http://golang.org/pkg/html/template/#Must, wraps a call to a function
returning (*Template, error) and panics if the error is non-nil.
So we don't need to that ourselves. Which is a good thing and makes code
cleaner.
BUG=None
TEST=None
R=jcgregorio@google.com
Review URL: https://codereview.chromium.org/642243004
diff --git a/experimental/webtry/webtry.go b/experimental/webtry/webtry.go
index 08201aa..e644d13 100644
--- a/experimental/webtry/webtry.go
+++ b/experimental/webtry/webtry.go
@@ -146,55 +146,37 @@
}
os.Chdir(cwd)
- codeTemplate, err = template.ParseFiles(filepath.Join(cwd, "templates/template.cpp"))
- if err != nil {
- panic(err)
- }
- gypTemplate, err = template.ParseFiles(filepath.Join(cwd, "templates/template.gyp"))
- if err != nil {
- panic(err)
- }
- indexTemplate, err = htemplate.ParseFiles(
+ codeTemplate = template.Must(template.ParseFiles(filepath.Join(cwd, "templates/template.cpp")))
+ gypTemplate = template.Must(template.ParseFiles(filepath.Join(cwd, "templates/template.gyp")))
+ indexTemplate = htemplate.Must(htemplate.ParseFiles(
filepath.Join(cwd, "templates/index.html"),
filepath.Join(cwd, "templates/titlebar.html"),
filepath.Join(cwd, "templates/sidebar.html"),
filepath.Join(cwd, "templates/content.html"),
filepath.Join(cwd, "templates/headercommon.html"),
filepath.Join(cwd, "templates/footercommon.html"),
- )
- if err != nil {
- panic(err)
- }
- iframeTemplate, err = htemplate.ParseFiles(
+ ))
+ iframeTemplate = htemplate.Must(htemplate.ParseFiles(
filepath.Join(cwd, "templates/iframe.html"),
filepath.Join(cwd, "templates/content.html"),
filepath.Join(cwd, "templates/headercommon.html"),
filepath.Join(cwd, "templates/footercommon.html"),
- )
- if err != nil {
- panic(err)
- }
- recentTemplate, err = htemplate.ParseFiles(
+ ))
+ recentTemplate = htemplate.Must(htemplate.ParseFiles(
filepath.Join(cwd, "templates/recent.html"),
filepath.Join(cwd, "templates/titlebar.html"),
filepath.Join(cwd, "templates/sidebar.html"),
filepath.Join(cwd, "templates/headercommon.html"),
filepath.Join(cwd, "templates/footercommon.html"),
- )
- if err != nil {
- panic(err)
- }
- workspaceTemplate, err = htemplate.ParseFiles(
+ ))
+ workspaceTemplate = htemplate.Must(htemplate.ParseFiles(
filepath.Join(cwd, "templates/workspace.html"),
filepath.Join(cwd, "templates/titlebar.html"),
filepath.Join(cwd, "templates/sidebar.html"),
filepath.Join(cwd, "templates/content.html"),
filepath.Join(cwd, "templates/headercommon.html"),
filepath.Join(cwd, "templates/footercommon.html"),
- )
- if err != nil {
- panic(err)
- }
+ ))
// The git command returns output of the format:
//