示例#1
0
func (cr *DataController) Update(id string, cx *goweb.Context) {
	cx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
	cx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*")
	cx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "PUT")
	data := new(dataContainer)
	data.Model = cx.PathParams["model"]
	errs := cx.Fill(&data.Data)
	if errs != nil {
		log.Print(errs)
		cx.RespondWithError(500)
	} else {
		bucket, berr := couchbase.GetBucket("http://localhost:8091/", "default", "mking.me")
		if berr != nil {
			log.Print(berr)
			cx.WriteResponse(data, http.StatusInternalServerError)
		} else {
			data.Data["id"] = id
			errr := bucket.Set(id, 0, data)
			if errr != nil {
				log.Print(errr)
				cx.WriteResponse(data.Data, http.StatusInternalServerError)
			} else {
				cx.WriteResponse(data.Data, http.StatusOK)
			}
		}
	}
}
示例#2
0
// for OPTIONS /api
func (cr *DataController) Options(cx *goweb.Context) {
	log.Print("wat")

	cx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*")
	cx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS")
	cx.RespondWithOK()
}
func (cr *ManifestController) ReadMany(cx *goweb.Context) {
	cx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
	bucket, err := couchbase.GetBucket("http://localhost:8091/", "default", "mking.me")
	if err != nil {
		log.Print(err)
	}

	rv := make(map[string]interface{})
	rv["stale"] = false
	vres, _ := bucket.View("manifest", "all", rv)
	if len(vres.Rows) > 0 {
		cx.WriteResponse(vres.Rows[0].Value, http.StatusOK)
	} else {
		cx.WriteResponse(make([]string, 0), http.StatusOK)
	}
}
示例#4
0
func (cr *DataController) Delete(id string, cx *goweb.Context) {
	cx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
	cx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*")
	cx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "DELETE")
	bucket, err := couchbase.GetBucket("http://localhost:8091/", "default", "mking.me")
	if err != nil {
		log.Print(err)
		cx.WriteResponse("", http.StatusInternalServerError)
	}
	rv := new(dataContainer)
	bucket.Get(id, &rv)
	derr := bucket.Delete(id)
	if derr != nil {
		log.Print(derr)
		cx.WriteResponse(rv.Data, http.StatusInternalServerError)
	} else {
		cx.WriteResponse(rv.Data, http.StatusOK)
	}
}
func (cr *ManifestController) Read(id string, cx *goweb.Context) {

	bucket, err := couchbase.GetBucket("http://localhost:8091/", "default", "mking.me")
	if err != nil {
		log.Print(err)
	}
	rv := new(manifestData)
	gerr := bucket.Get(id, &rv)
	if gerr != nil {
		cx.WriteResponse(rv, http.StatusNotFound)
	} else {
		if rv != nil {
			cx.WriteResponse(rv, http.StatusOK)
		} else {
			cx.WriteResponse(rv, http.StatusNotFound)
		}
	}

}
示例#6
0
func (cr *DataController) Read(id string, cx *goweb.Context) {
	cx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
	cx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*")
	cx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "GET")
	bucket, err := couchbase.GetBucket("http://localhost:8091/", "default", "mking.me")
	if err != nil {
		log.Print(err)
	}
	rv := new(dataContainer)
	gerr := bucket.Get(id, &rv)
	if gerr != nil {
		cx.WriteResponse(rv.Data, http.StatusNotFound)
	} else {
		if rv != nil {
			cx.WriteResponse(rv.Data, http.StatusOK)
		} else {
			cx.WriteResponse(rv.Data, http.StatusNotFound)
		}
	}
}
示例#7
0
func (cr *DataController) ReadMany(cx *goweb.Context) {
	cx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
	cx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*")
	cx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "GET")
	bucket, err := couchbase.GetBucket("http://localhost:8091/", "default", "mking.me")
	if err != nil {
		log.Print(err)
	}

	rv := make(map[string]interface{})
	rv["stale"] = false
	vres, verr := bucket.View(cx.PathParams["model"], "all", rv)
	if verr != nil {
		cx.WriteResponse(make([]string, 0), http.StatusNotFound)
	} else {
		if len(vres.Rows) > 0 {
			cx.WriteResponse(vres.Rows[0].Value, http.StatusOK)
		} else {
			cx.WriteResponse(make([]string, 0), http.StatusOK)
		}
	}
}
示例#8
0
func (cr *DataController) UpdateMany(cx *goweb.Context) {
	cx.RespondWithStatus(http.StatusNotImplemented)
}
示例#9
0
func (p *Product) Fill(cx *goweb.Context) {
	cx.Fill(&p)
}
示例#10
0
func (p *Person) Fill(cx *goweb.Context) {
	cx.Fill(&p)
}
示例#11
0
func (cr *ManifestController) DeleteMany(cx *goweb.Context) {
	cx.RespondWithStatus(http.StatusNotImplemented)
}