github.com/jgbaldwinbrown/perf@v0.1.1/analysis/app/app.go (about)

     1  // Copyright 2017 The Go Authors.  All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Package app implements the performance data analysis server.
     6  package app
     7  
     8  import (
     9  	"net/http"
    10  
    11  	"golang.org/x/perf/storage"
    12  )
    13  
    14  // App manages the analysis server logic.
    15  // Construct an App instance and call RegisterOnMux to connect it with an HTTP server.
    16  type App struct {
    17  	// StorageClient is used to talk to the storage server.
    18  	StorageClient *storage.Client
    19  
    20  	// BaseDir is the directory containing the "template" directory.
    21  	// If empty, the current directory will be used.
    22  	BaseDir string
    23  }
    24  
    25  // RegisterOnMux registers the app's URLs on mux.
    26  func (a *App) RegisterOnMux(mux *http.ServeMux) {
    27  	mux.HandleFunc("/", a.index)
    28  	mux.HandleFunc("/search", a.search)
    29  	mux.HandleFunc("/compare", a.compare)
    30  	mux.HandleFunc("/trend", a.trend)
    31  }
    32  
    33  // search handles /search.
    34  // This currently just runs the compare handler, until more analysis methods are implemented.
    35  func (a *App) search(w http.ResponseWriter, r *http.Request) {
    36  	if err := r.ParseForm(); err != nil {
    37  		http.Error(w, err.Error(), 500)
    38  		return
    39  	}
    40  	if r.Header.Get("Accept") == "text/plain" || r.Header.Get("X-Benchsave") == "1" {
    41  		// TODO(quentin): Switch to real Accept negotiation when golang/go#19307 is resolved.
    42  		// Benchsave sends both of these headers.
    43  		a.textCompare(w, r)
    44  		return
    45  	}
    46  	// TODO(quentin): Intelligently choose an analysis method
    47  	// based on the results from the query, once there is more
    48  	// than one analysis method.
    49  	//q := r.Form.Get("q")
    50  	a.compare(w, r)
    51  }