| 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))
|
| +}
|
|
|