Пример #1
0
func (o *Otama) Insert(filename string) (id string, err error) {
	var _id C.otama_id_t
	var hexid [C.OTAMA_ID_HEXSTR_LEN]C.char

	ret := C.otama_insert_file(o.otama, &_id, C.CString(filename))
	if ret != C.OTAMA_STATUS_OK {
		buf := bytes.NewBufferString("otama_insert_file: ")
		buf.WriteString(get_status_message(ret))
		err = errors.New(buf.String())
	}

	C.otama_id_bin2hexstr(&hexid[0], &_id)
	return C.GoStringN(&hexid[0], C.OTAMA_ID_HEXSTR_LEN), err
}
Пример #2
0
func make_results(raw_results *C.otama_result_t) []OtamaResult {
	var hexid [C.OTAMA_ID_HEXSTR_LEN]C.char
	var result_num = int(C.otama_result_count(raw_results))
	var results []OtamaResult
	var value *C.otama_variant_t

	if result_num != 0 {
		results = make([]OtamaResult, result_num)
	}

	for i := 0; i < result_num; i++ {
		value = C.otama_result_value(raw_results, C.int(i))
		C.otama_id_bin2hexstr(&hexid[0], C.otama_result_id(raw_results, C.int(i)))

		results[i] = OtamaResult{Id: C.GoStringN(&hexid[0], C.OTAMA_ID_HEXSTR_LEN),
			Similarity: variant2goobj(value)}
	}

	return results
}