Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Unified Diff: tools/bug_chomper/src/server/server.go

Issue 661613004: bug_chomper: Cleanup template initialization. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/bug_chomper/src/server/server.go
diff --git a/tools/bug_chomper/src/server/server.go b/tools/bug_chomper/src/server/server.go
index 1388d00b9349be37e6032b36d36a2ce736d19d26..7fdae93c7bd17662d6831c32eed2a93087bcd816 100644
--- a/tools/bug_chomper/src/server/server.go
+++ b/tools/bug_chomper/src/server/server.go
@@ -20,8 +20,9 @@ import (
"log"
"net/http"
"net/url"
- "path"
+ "os"
"path/filepath"
+ "runtime"
"strconv"
"strings"
"time"
@@ -49,20 +50,31 @@ var (
)
var (
- scheme = "http"
-
- curdir, _ = filepath.Abs(".")
- templatePath, _ = filepath.Abs("templates")
- templates = template.Must(template.ParseFiles(
- path.Join(templatePath, "bug_chomper.html"),
- path.Join(templatePath, "submitted.html"),
- path.Join(templatePath, "error.html")))
+ // templates is the list of html templates used by bug_chomper.
+ templates *template.Template = nil
+ scheme = "http"
hashKey = securecookie.GenerateRandomKey(32)
blockKey = securecookie.GenerateRandomKey(32)
secureCookie = securecookie.New(hashKey, blockKey)
)
+func init() {
+ // Change the current working directory to two directories up from this
+ // source file so that we can read templates.
+ _, filename, _, _ := runtime.Caller(0)
+ cwd := filepath.Join(filepath.Dir(filename), "../..")
+ if err := os.Chdir(cwd); err != nil {
+ log.Fatal(err)
+ }
+
+ templates = template.Must(template.ParseFiles(
+ filepath.Join(cwd, "templates/bug_chomper.html"),
tfarina 2014/10/15 22:18:14 cwd results in the abs path where running ./run_se
+ filepath.Join(cwd, "templates/submitted.html"),
+ filepath.Join(cwd, "templates/error.html"),
+ ))
+}
+
// SessionState contains data for a given session.
type SessionState struct {
IssueTracker *issue_tracker.IssueTracker
@@ -363,7 +375,7 @@ func main() {
http.HandleFunc("/", handleRoot)
http.HandleFunc(oauthCallbackPath, handleOAuth2Callback)
- http.Handle("/res/", http.FileServer(http.Dir(curdir)))
+ http.Handle("/res/", http.FileServer(http.Dir("./")))
log.Println("Server is running at " + scheme + "://" + localHost + *port)
var err error
if *public {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698