예제 #1
0
func ExampleDataset_Index() {
	d1 := &storage.Dataset{Name: "Iris"}
	d2 := &storage.Dataset{Name: "Iris"}

	db, _ := redis.NewDB(config)
	storage := storage.New(db)

	storage.Clean()
	storage.Insert(d1)
	storage.Insert(d2)

	req, _ := http.NewRequest("GET", "/datasets/", nil)
	dataset := &api.DatasetHandler{storage}

	resp := httptest.NewRecorder()
	dataset.Index(resp, req, nil)

	datasets := []string{}
	unmarshaller.IoReader(resp.Body, &datasets)

	fmt.Printf("%d\n", resp.Code)
	fmt.Printf("Size %d", len(datasets))

	// Output:
	// 200
	// Size 2
}
예제 #2
0
func (handler *DatasetHandler) Create(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	puaro.HTTPLogger(r)

	storage := handler.Storage
	dataset := storage.NewDataset("")

	unmarshaller.IoReader(r.Body, dataset)

	err := storage.Insert(dataset)
	if err != nil {
		w.WriteHeader(400)
		fmt.Fprint(w, err)
		return
	}

	w.WriteHeader(200)
}
예제 #3
0
파일: jobs.go 프로젝트: datagentleman/puaro
func (handler *JobHandler) Create(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	puaro.HTTPLogger(r)
	cluster := handler.Cluster

	job := &models.Job{}
	if err := unmarshaller.IoReader(r.Body, job); err != nil {
		w.WriteHeader(400)
		fmt.Fprint(w, err)
		return
	}

	if err := cluster.AddJob(job); err != nil {
		w.WriteHeader(400)
		fmt.Fprint(w, err)
		return
	}

	w.WriteHeader(200)
}
예제 #4
0
func (handler *InstanceHandler) Create(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	storage := handler.Storage
	dataset := storage.NewDataset(params.ByName("dataset"))

	instance := &instance.Attributes{}
	if err := unmarshaller.IoReader(r.Body, instance); err != nil {
		w.WriteHeader(400)
		fmt.Fprint(w, err)
		return
	}

	collection := dataset.NewListCollection(params.ByName("collection"))
	if err := collection.Insert(instance); err != nil {
		w.WriteHeader(400)
		fmt.Fprint(w, err)
		return
	}

	w.WriteHeader(200)
}
예제 #5
0
func (handler *FactoryHandler) Register(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	factory := &models.Factory{}
	cluster := handler.Cluster

	if err := unmarshaller.IoReader(r.Body, factory); err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		fmt.Fprint(w, err)
		return
	}

	factory.Host = r.RemoteAddr

	if err := cluster.Register(factory); err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		fmt.Fprint(w, err)
		return
	}

	w.WriteHeader(http.StatusOK)
}