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

Unified Diff: fuzzer/go/fuzzer/main.go

Issue 911143003: skeleton for fuzzer; contains makefile and front end server (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: ;switch fuzzer to new metrics callback init Created 5 years, 10 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 | « fuzzer/go/config/config.go ('k') | fuzzer/package.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fuzzer/go/fuzzer/main.go
diff --git a/fuzzer/go/fuzzer/main.go b/fuzzer/go/fuzzer/main.go
new file mode 100644
index 0000000000000000000000000000000000000000..b1160152c97b946f1e554eb61b61408a9369b28e
--- /dev/null
+++ b/fuzzer/go/fuzzer/main.go
@@ -0,0 +1,84 @@
+package main
+
+import (
+ "flag"
+ htemplate "html/template"
+ "math/rand"
+ "net/http"
+ "os"
+ "path/filepath"
+ "runtime"
+ "time"
+
+ "github.com/BurntSushi/toml"
+ "github.com/fiorix/go-web/autogzip"
+ metrics "github.com/rcrowley/go-metrics"
+ "github.com/skia-dev/glog"
+ "skia.googlesource.com/buildbot.git/fuzzer/go/config"
+ "skia.googlesource.com/buildbot.git/go/common"
+)
+
+var (
+ // indexTemplate is the main index.html page we serve.
+ indexTemplate *htemplate.Template = nil
+
+ requestsCounter = metrics.NewRegisteredCounter("requests", metrics.DefaultRegistry)
+)
+
+// Command line flags.
+var (
+ configFilename = flag.String("config", "fuzzer.toml", "Configuration filename")
+)
+
+func Init() {
+ rand.Seed(time.Now().UnixNano())
+
+ common.InitWithMetricsCB("fuzzer", func() string {
+ if _, err := toml.DecodeFile(*configFilename, &config.Fuzzer); err != nil {
+ glog.Fatalf("Failed to decode config file: %s", err)
+ }
+ return config.Fuzzer.FrontEnd.GraphiteServer
+ })
+
+ if config.Fuzzer.FrontEnd.ResourcePath == "" {
+ _, filename, _, _ := runtime.Caller(0)
+ config.Fuzzer.FrontEnd.ResourcePath = filepath.Join(filepath.Dir(filename), "../..")
+ }
+
+ path, err := filepath.Abs(config.Fuzzer.FrontEnd.ResourcePath)
+ if err != nil {
+ glog.Fatalf("Couldn't get absolute path to fuzzer resources: %s", err)
+ }
+ if err := os.Chdir(path); err != nil {
+ glog.Fatal(err)
+ }
+
+ indexTemplate = htemplate.Must(htemplate.ParseFiles(
+ filepath.Join(path, "templates/index.html"),
+ filepath.Join(path, "templates/header.html"),
+ filepath.Join(path, "templates/footer.html"),
+ ))
+
+}
+
+// mainHandler handles the GET and POST of the main page.
+func mainHandler(w http.ResponseWriter, r *http.Request) {
+ glog.Infof("Main Handler: %q\n", r.URL.Path)
+ requestsCounter.Inc(1)
+ if r.Method == "GET" {
+ // Expand the template.
+ w.Header().Set("Content-Type", "text/html")
+ if err := indexTemplate.Execute(w, struct{}{}); err != nil {
+ glog.Errorf("Failed to expand template: %q\n", err)
+ }
+ }
+}
+
+func main() {
+ flag.Parse()
+ Init()
+ // Resources are served directly
+ http.Handle("/res/", autogzip.Handle(http.FileServer(http.Dir("./"))))
+ http.HandleFunc("/", autogzip.HandleFunc(mainHandler))
+ glog.Fatal(http.ListenAndServe(config.Fuzzer.FrontEnd.Port, nil))
+}
« no previous file with comments | « fuzzer/go/config/config.go ('k') | fuzzer/package.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698