mirror of
https://github.com/c0re100/gotdlib.git
synced 2026-02-21 20:20:17 +01:00
Merge branch 'master' of https://github.com/zelenin/go-tdlib
This commit is contained in:
commit
d194b79c3c
4 changed files with 309 additions and 93 deletions
|
|
@ -102,6 +102,30 @@ func (instance *tdlib) receive(timeout time.Duration) (*Response, error) {
|
|||
return &resp, nil
|
||||
}
|
||||
|
||||
func Execute(req Request) (*Response, error) {
|
||||
data, _ := json.Marshal(req)
|
||||
|
||||
query := C.CString(string(data))
|
||||
defer C.free(unsafe.Pointer(query))
|
||||
result := C.td_execute(query)
|
||||
if result == nil {
|
||||
return nil, errors.New("request can't be parsed")
|
||||
}
|
||||
|
||||
data = []byte(C.GoString(result))
|
||||
|
||||
var resp Response
|
||||
|
||||
err := json.Unmarshal(data, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp.Data = data
|
||||
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
type JsonClient struct {
|
||||
id int
|
||||
}
|
||||
|
|
@ -127,27 +151,7 @@ func (jsonClient *JsonClient) Send(req Request) {
|
|||
// Returned pointer will be deallocated by TDLib during next call to td_json_client_receive or td_json_client_execute
|
||||
// in the same thread, so it can't be used after that.
|
||||
func (jsonClient *JsonClient) Execute(req Request) (*Response, error) {
|
||||
data, _ := json.Marshal(req)
|
||||
|
||||
query := C.CString(string(data))
|
||||
defer C.free(unsafe.Pointer(query))
|
||||
result := C.td_execute(query)
|
||||
if result == nil {
|
||||
return nil, errors.New("request can't be parsed")
|
||||
}
|
||||
|
||||
data = []byte(C.GoString(result))
|
||||
|
||||
var resp Response
|
||||
|
||||
err := json.Unmarshal(data, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp.Data = data
|
||||
|
||||
return &resp, nil
|
||||
return Execute(req)
|
||||
}
|
||||
|
||||
type meta struct {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue