任务rpc
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.1 KiB

package taskrpc
import (
"encoding/json"
"errors"
"log"
)
func DoTask(dbname, siteid, userId, task_type string, url ...string) (bool, error) {
if dbname == "" || userId == "" || task_type == ""{
return false, errors.New("参数错误")
}
conn, err := rpc_server_conn(url...)
if err != nil {
return false, err
}
defer conn.Close()
data := DoTaskParam{}
data.Dbname = dbname
data.SiteId = siteid
data.UserId = userId
data.Type = task_type
req, err := SetReqData(data)
if err != nil {
log.Println("DoTask crypter error:", err)
return false, err
}
res := &Response{}
err = conn.DoTask(req, res)
if err != nil {
log.Println("taskrpc DoTask error:", err)
return false, err
}
res_data_de, err := GetResData(res)
if err != nil {
return false, err
}
if res_data_de == "" {
return false, nil
}
var task_res bool
err = json.Unmarshal([]byte(res_data_de), &task_res)
if err != nil {
return false, err
}
return task_res, nil
}