供应商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.

62 lines
1013 B

3 years ago
3 years ago
  1. package supplierrpc
  2. import (
  3. "encoding/json"
  4. "errors"
  5. )
  6. type GetParam struct {
  7. SiteId string `json:"site_id"`
  8. Dbname string `json:"database"`
  9. Id string `json:"id"`
  10. }
  11. type GetUuidParam struct {
  12. SiteId string `json:"site_id"`
  13. Dbname string `json:"database"`
  14. Uuid string `json:"uuid"`
  15. }
  16. func Get(site_id, dbname, id string, url ...string) (map[string]string, error) {
  17. if dbname == "" || id == "" {
  18. return nil, errors.New("参数错误")
  19. }
  20. conn, err := rpc_server_conn(url...)
  21. if err != nil {
  22. return nil, err
  23. }
  24. defer conn.Close()
  25. arg := GetParam{site_id, dbname, id}
  26. req, err := SetReqData(arg)
  27. if err != nil {
  28. return nil, err
  29. }
  30. res := &Params{}
  31. err = conn.Get(req, res)
  32. if err != nil {
  33. return nil, err
  34. }
  35. res_data_de, err := GetData(res)
  36. if err != nil {
  37. return nil, err
  38. }
  39. if res_data_de == "" {
  40. return nil, nil
  41. }
  42. var res_arr map[string]string
  43. err = json.Unmarshal([]byte(res_data_de), &res_arr)
  44. if err != nil {
  45. return nil, err
  46. }
  47. return res_arr, nil
  48. }