// Generic operation that returns objects func (client *Client) objOp(funcName, space, key string, conds []Condition) ObjectChannel { objCh := make(chan Object, CHANNEL_BUFFER_SIZE) var status C.enum_hyperdex_client_returncode var C_attrs *C.struct_hyperdex_client_attribute var C_attrs_sz C.size_t var C_attr_checks *C.struct_hyperdex_client_attribute_check var C_attr_checks_sz C.size_t var err error if conds != nil { C_attr_checks, C_attr_checks_sz, err = client.newCAttributeCheckList(conds) if err != nil { objCh <- Object{ Err: err, } close(objCh) return objCh } } var req_id int64 switch funcName { case "get": req_id = int64(C.hyperdex_client_get(client.ptr, C.CString(space), C.CString(key), C.size_t(bytesOf(key)), &status, &C_attrs, &C_attrs_sz)) case "search": req_id = int64(C.hyperdex_client_search(client.ptr, C.CString(space), C_attr_checks, C_attr_checks_sz, &status, &C_attrs, &C_attrs_sz)) } if req_id < 0 { objCh <- Object{Err: newInternalError(status, C.GoString(C.hyperdex_client_error_message(client.ptr)))} close(objCh) return objCh } req := request{ id: req_id, status: &status, } switch funcName { case "get": req.success = func() { attrs, err := client.newAttributeListFromC(C_attrs, C_attrs_sz) if err != nil { objCh <- Object{Err: err} close(objCh) return } objCh <- Object{Err: nil, Key: key, Attrs: attrs} close(objCh) if C_attrs_sz > 0 { C.hyperdex_client_destroy_attrs(C_attrs, C_attrs_sz) } } req.failure = objChannelFailureCallback(objCh) case "search": req.isIterator = true req.success = func() { // attrs, err := newAttributeListFromC(C_attrs, C_attrs_sz) attrs, err := client.newAttributeListFromC(C_attrs, C_attrs_sz) if err != nil { objCh <- Object{Err: err} close(objCh) return } if C_attrs_sz > 0 { C.hyperdex_client_destroy_attrs(C_attrs, C_attrs_sz) } objCh <- Object{Attrs: attrs} } req.failure = objChannelFailureCallback(objCh) req.complete = func() { close(objCh) } } client.requests = append(client.requests, req) return objCh }
func (client *Client) SortedSearch(space string, conds []Condition, sort_by string, limit int, maxmin int) ObjectChannel { objCh := make(chan Object, CHANNEL_BUFFER_SIZE) var status C.enum_hyperdex_client_returncode var C_attrs *C.struct_hyperdex_client_attribute var C_attrs_sz C.size_t var C_attr_checks *C.struct_hyperdex_client_attribute_check var C_attr_checks_sz C.size_t var err error if conds != nil { C_attr_checks, C_attr_checks_sz, err = client.newCAttributeCheckList(conds) if err != nil { objCh <- Object{ Err: err, } close(objCh) return objCh } } req_id := int64(C.hyperdex_client_sorted_search(client.ptr, C.CString(space), C_attr_checks, C_attr_checks_sz, C.CString(sort_by), C.uint64_t(limit), C.int(maxmin), &status, &C_attrs, &C_attrs_sz)) if req_id < 0 { objCh <- Object{Err: newInternalError(status, C.GoString(C.hyperdex_client_error_message(client.ptr)))} close(objCh) return objCh } req := request{ id: req_id, status: &status, isIterator: true, success: func() { // attrs, err := newAttributeListFromC(C_attrs, C_attrs_sz) attrs, err := client.newAttributeListFromC(C_attrs, C_attrs_sz) if err != nil { objCh <- Object{Err: err} close(objCh) return } if C_attrs_sz > 0 { C.hyperdex_client_destroy_attrs(C_attrs, C_attrs_sz) } objCh <- Object{Attrs: attrs} }, failure: objChannelFailureCallback(objCh), complete: func() { close(objCh) }, } client.requests = append(client.requests, req) return objCh }