任务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

  1. package taskrpc
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "log"
  6. )
  7. func DoTask(dbname, siteid, userId, task_type string, url ...string) (bool, error) {
  8. if dbname == "" || userId == "" || task_type == ""{
  9. return false, errors.New("参数错误")
  10. }
  11. conn, err := rpc_server_conn(url...)
  12. if err != nil {
  13. return false, err
  14. }
  15. defer conn.Close()
  16. data := DoTaskParam{}
  17. data.Dbname = dbname
  18. data.SiteId = siteid
  19. data.UserId = userId
  20. data.Type = task_type
  21. req, err := SetReqData(data)
  22. if err != nil {
  23. log.Println("DoTask crypter error:", err)
  24. return false, err
  25. }
  26. res := &Response{}
  27. err = conn.DoTask(req, res)
  28. if err != nil {
  29. log.Println("taskrpc DoTask error:", err)
  30. return false, err
  31. }
  32. res_data_de, err := GetResData(res)
  33. if err != nil {
  34. return false, err
  35. }
  36. if res_data_de == "" {
  37. return false, nil
  38. }
  39. var task_res bool
  40. err = json.Unmarshal([]byte(res_data_de), &task_res)
  41. if err != nil {
  42. return false, err
  43. }
  44. return task_res, nil
  45. }