Example #1
0
File: server.go Project: Jonty/pat
func ServeWithLab(lab Laboratory) {
	benchmarker.WithConfiguredWorkerAndSlaves(func(worker benchmarker.Worker) error {
		r := mux.NewRouter()
		ctx := &serverContext{r, lab, worker}

		r.Methods("GET").Path("/experiments/").HandlerFunc(handler(ctx.handleListExperiments))
		r.Methods("GET").Path("/experiments/{name}.csv").HandlerFunc(csvHandler(ctx.handleGetExperiment)).Name("csv")
		r.Methods("GET").Path("/experiments/{name}").HandlerFunc(handler(ctx.handleGetExperiment)).Name("experiment")
		r.Methods("POST").Path("/experiments/").HandlerFunc(handler(ctx.handlePush))
		r.Methods("GET").Path("/").HandlerFunc(redirectBase)

		http.Handle("/ui/", http.StripPrefix("/ui/", http.FileServer(http.Dir("ui"))))
		http.Handle("/", r)
		bind()

		return nil
	})
}
Example #2
0
	}

	var ok, err = worker.Validate(params.workload)

	if !ok {
		fmt.Printf("Invalid workload: '%s'\n\n", err)
		fmt.Println("Available workloads:\n")
		worker.Visit(PrintWorkload)
		return err
	}

	return then()
}

var WithConfiguredWorkerAndSlaves = func(fn func(worker benchmarker.Worker) error) error {
	return benchmarker.WithConfiguredWorkerAndSlaves(fn)
}

var LaboratoryFactory = func(store Store) (lab Laboratory) {
	lab = NewLaboratory(store)
	return
}

var BlockExit = func() {
	for {
		in := make([]byte, 1)
		os.Stdin.Read(in)
		if string(in) == "q" {
			return
		}
	}