Closed a1div0 closed 10 months ago
field names in the response are written in lowercase letters
It is a thing for structs, but in case of map[string]interface{}
any string key is public.
Call("localhost:3301", "crud.replave_object_many", args)
We have proper crud request API in go-tarantool/crud (see example). Try to use it instead of your custom call. It already covers various things, including marshaling response to a structure with public fields.
Error = null, it's right. In data = void struct - it's not right.
It is also likely that you had received a Lua error in response. In your implementation, it won't be in err
, but in resp.Data
The resp.Data is a []insterface
of map[interface{}/string]insterface{}
. You have access to the all data in the response. But you need to make type-casts manually (see examples for the connector). Or you could decode the response into a data structure directly:
https://github.com/tarantool/go-tarantool/blob/a664c6bbb6a1f21aecfccf199858e19a21857700/example_custom_unpacking_test.go#L68-L78
I recommend to use crud submodule from the connector to make requests to crud. We implement special requests + read result helpers:
So you don't need to reimplement this logic in your code in fact.
We have proper crud request API in go-tarantool/crud (see example). Try to use it instead of your custom call. It already covers various things, including marshaling response to a structure with public fields.
I took crud as an example. If I still need the result of calling call
?
It is also likely that you had received a Lua error in response. In your implementation, it won't be in err, but in resp.Data
In my example there is definitely no error there.
It is also likely that you had received a Lua error in response. In your implementation, it won't be in err, but in resp.Data
In my example there is definitely no error there.
In the example you had provided you call non-existing crud.replave_object_many
If I still need the result of calling
call
?
Then "each map[string] value is public" is still applicable.
type resp struct {
val1 string // <- private
Val2 string // <- public
}
type respMap map[string]interface{
"val1": "someval" // <- public
"Val2": "someval" // <- public
}
We have proper crud request API in go-tarantool/crud (see example). Try to use it instead of your custom call. It already covers various things, including marshaling response to a structure with public fields.
I took crud as an example. If I still need the result of calling
call
?
So you need to make typecasts from interface{}
manually to fetch the result data, as example (I don't recommend that way):
https://github.com/tarantool/go-tarantool/blob/master/tarantool_test.go#L2452
Or parse it in some struct{} type with *Typed()
requests.
So you don't need to reimplement this logic in your code in fact.
Unfortunately no. I use the connector for load tests on K6 (JavaScript). At a minimum, you cannot return more than one result.
In the example you had provided you call non-existing crud.replave_object_many
crud.replase_object_many
So you don't need to reimplement this logic in your code in fact.
Unfortunately no. I use the connector for load tests on K6 (JavaScript). At a minimum, you cannot return more than one result.
Could you please give an example?
Then "each map[string] value is public" is still applicable.
It may be applicable, but I see something else. Maybe of course I'm doing something wrong. For example, we convert the answer to JSON:
func (Tarantool) Call(conn *tarantool.Connection, fnName string, args interface{}) CallResponse {
req := tarantool.NewCallRequest(fnName).Args(args)
future := conn.Do(req)
resp, err := future.Get()
if err != nil {
return CallResponse{nil, err.Error()}
}
b, _ := json.Marshal(resp.Data[0])
return CallResponse{ resp.Data[0] , string(b) }
}
Output:
null, "null"
Could you please give an example?
My case:
Output:
null, "null"
What are Call()
arguments and what resp.Data
contains in that case?
msgpack
decodes to map[interface{}]interface{}
by default, but decoding/json.Marshal()
requires map[string]interface{}
. I even don't undestand how your code works at all (and I don't have access to tarantool/k6-tarantool
).
Please, check json.Marshal()
error result too.
I really needed to convert the result from map[instance{}]instance{}
to map[string]instance{}
Reproducer
crud.replace
, orcrud.insert
or any.Call("localhost:3301", "crud.replave_object_many", args)
{ "request_id": 104, "code": 0, "error": "", "data": [ {}, null ], "pos": [], "meta_data": [], "sql_info": { "affected_count": 0, "info_autoincrement_ids": [] } }
crud.replace('customers', {1, box.NULL, 'Alice', 22})
Specifically in this:
Problem
The problem is that the field names in the response are written in lowercase letters. Thus, these are private fields and we do not have access to them. Therefore, in the end we see an empty response, although it is not empty.