采购管理员接口远程调用
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.

52 lines
814 B

1 year ago
1 year ago
1 year ago
  1. package adminrpc
  2. import (
  3. "encoding/json"
  4. "errors"
  5. )
  6. func GetByToken(dbname, token string, url ...string) (map[string]string, error) {
  7. if dbname == "" || token == "" {
  8. return nil, errors.New("参数错误")
  9. }
  10. conn, err := rpc_server_conn(url...)
  11. if err != nil {
  12. return nil, err
  13. }
  14. defer conn.Close()
  15. data := GetByTokenReq{}
  16. data.Token = token
  17. data.Dbname = dbname
  18. req, err := SetReqData(data)
  19. if err != nil {
  20. return nil, err
  21. }
  22. res := &Response{}
  23. err = conn.GetByToken(req, res)
  24. if err != nil {
  25. return nil, err
  26. }
  27. res_data_de, err := GetResData(res)
  28. if err != nil {
  29. return nil, err
  30. }
  31. if res_data_de == "" {
  32. return nil, nil
  33. }
  34. var res_arr map[string]string
  35. err = json.Unmarshal([]byte(res_data_de), &res_arr)
  36. if err != nil {
  37. return nil, err
  38. }
  39. return res_arr, nil
  40. }