Beispiel #1
0
func getKey(serv OrchioReadService, name, key, ref string) string {

	data, mdata, err := datastore.GetKey(name, key, ref)
	logError("Orchio::getKey:", err)

	responseCode := 200
	response := updateResponse(serv.ResponseBuilder(), "")

	// Guard clause for 404 and 500 errors.
	if mdata == "" {
		var msgCode string
		if data == "" {
			responseCode = 404
			msgCode = "items_not_found"
		} else {
			responseCode = 500
			msgCode = "internal_error"
		}
		errorMsgBody := refErrorMsgBody(responseCode, msgCode, name, key, ref)
		completeTheResponse(response, responseCode, errorMsgBody)
		return ""
	}

	if ref == "" {
		var tmpMdata datastore.Metadata
		if err := json.Unmarshal([]byte(mdata), &tmpMdata); err == nil {
			ref = tmpMdata.Ref
		}
	}
	response.AddHeader("Content-Location", locationString(name, key, ref))
	response.AddHeader("Etag", strconv.Quote(ref))
	completeTheResponse(response, responseCode, data)
	return ""
}
Beispiel #2
0
func checkRefValue(name, key, ref string) int {
	data, _, err := datastore.GetKey(name, key, ref)
	if err != nil {
		return 500
	} else if data == "" {
		return 404
	}
	return 0
}
Beispiel #3
0
func getRefValue(name, key string) string {
	if _, mdata, err := datastore.GetKey(name, key, ""); err == nil {
		if mdata != "" {
			var jmctmp datastore.Metadata
			if err := json.Unmarshal([]byte(mdata), &jmctmp); err == nil {
				return jmctmp.Ref
			}
		}
	}
	return ""
}
Beispiel #4
0
func itemAlreadyPresent(name, key string) bool {
	if data, _, err := datastore.GetKey(name, key, ""); err == nil {
		return (data != "")
	}
	return false
}