Example #1
0
func couchDbGetDoc(w http.ResponseWriter, r *http.Request) {
	_, _, bucket, docId := checkDocId(w, r)
	if bucket == nil || docId == "" {
		return
	}
	res := GetItem(bucket, []byte(docId), VBActive)
	if res == nil || res.Status != gomemcached.SUCCESS {
		http.Error(w, `{"error": "not_found", "reason": "missing"}`, 404)
		return
	}
	// TODO: Content Type, Accepts, much to leverage from sync_gateway.
	w.Header().Add("X-Couchbase-Meta", walrus.MakeMeta(docId))
	w.Write(res.Body)
}
Example #2
0
func couchDbGetDesignDoc(w http.ResponseWriter, r *http.Request) {
	_, _, bucket, ddocId := checkDocId(w, r)
	if bucket == nil || ddocId == "" {
		return
	}
	ddocIdFull := "_design/" + ddocId
	body, err := bucket.GetDDoc(ddocIdFull)
	if err != nil {
		http.Error(w, fmt.Sprintf("getDDoc err: %v, ddocIdFull: %v",
			err, ddocIdFull), 500)
		return
	}
	if body == nil {
		http.Error(w, "Not Found", 404)
		return
	}
	w.Header().Add("X-Couchbase-Meta", walrus.MakeMeta(ddocIdFull))
	w.Write(body)
}