Chromium Code Reviews| Index: perf/server/perf.go |
| diff --git a/perf/server/perf.go b/perf/server/perf.go |
| index 0d12dc5dbf015296f7aab4d59f4647aa7e216160..e70011e700594f9bc880c0760c42b82713bdcc44 100644 |
| --- a/perf/server/perf.go |
| +++ b/perf/server/perf.go |
| @@ -1,3 +1,7 @@ |
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be found |
| +// in the LICENSE file. |
| + |
| package main |
| import ( |
| @@ -30,7 +34,13 @@ var ( |
| // flags |
| var ( |
| - port = flag.String("port", ":8000", "HTTP service address (e.g., ':8000')") |
| + port = flag.String("port", ":8000", "HTTP service address (e.g., ':8000')") |
| + doOauth = flag.Bool("oauth", true, "Run through the OAuth 2.0 flow on startup.") |
| + gitRepoDir = flag.String("git_repo_dir", "../../../skia", "Directory location for the Skia repo.") |
| +) |
| + |
| +var ( |
| + data *Data |
|
mtklein
2014/06/15 15:12:12
Having data global smells a little to me. I think
jcgregorio
2014/06/16 02:46:25
Data will be protected with a Mutex once the auto
|
| ) |
| func init() { |
| @@ -96,6 +106,15 @@ func reportError(w http.ResponseWriter, r *http.Request, err error, message stri |
| http.Error(w, message, 500) |
| } |
| +// jsonHandler handles the GET for the JSON requests. |
| +func jsonHandler(w http.ResponseWriter, r *http.Request) { |
| + log.Printf("Main Handler: %q\n", r.URL.Path) |
|
mtklein
2014/06/15 15:12:12
-> JSON Handler: ?
jcgregorio
2014/06/16 02:46:25
Done.
jcgregorio
2014/06/16 02:46:25
Done.
|
| + if r.Method == "GET" { |
| + w.Header().Set("Content-Type", "application/json") |
| + data.AsJSON(w) |
| + } |
| +} |
| + |
| // mainHandler handles the GET and POST of the main page. |
| func mainHandler(w http.ResponseWriter, r *http.Request) { |
| log.Printf("Main Handler: %q\n", r.URL.Path) |
| @@ -109,9 +128,20 @@ func mainHandler(w http.ResponseWriter, r *http.Request) { |
| func main() { |
| flag.Parse() |
| + |
| + log.Println("Begin loading data.") |
| + var err error |
| + data, err = NewData(*doOauth, *gitRepoDir) |
| + if err != nil { |
| + log.Fatalln("Failed initial load of data from BigQuery: ", err) |
| + } |
| + |
| // Resources are served directly. |
| http.Handle("/res/", autogzip.Handle(http.FileServer(http.Dir("./")))) |
| http.HandleFunc("/", autogzip.HandleFunc(mainHandler)) |
| + http.HandleFunc("/json/", autogzip.HandleFunc(jsonHandler)) |
| + |
| + log.Println("Ready to serve.") |
| log.Fatal(http.ListenAndServe(*port, nil)) |
| } |