商品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.

74 lines
1.2 KiB

  1. package productrpc
  2. import (
  3. "encoding/json"
  4. // "strconv"
  5. // "time"
  6. "github.com/golang/protobuf/proto"
  7. )
  8. /**
  9. * id获取商品信息
  10. * 2021/08/20
  11. * GZ
  12. */
  13. func Get(site_id, dbname, id string, field string, url ...string) (map[string]string, error) {
  14. conn, err := rpc_server_conn(url...)
  15. if err != nil {
  16. return nil, err
  17. }
  18. defer conn.Close()
  19. req := &GetRequest{proto.String(site_id), proto.String(dbname), proto.String(id), proto.String(field), nil}
  20. res := &GetResponse{}
  21. err = conn.Get(req, res)
  22. if err != nil {
  23. return nil, err
  24. }
  25. value := res.GetValue()
  26. var data map[string]string
  27. err = json.Unmarshal(value, &data)
  28. return data, err
  29. }
  30. /**
  31. * uuid获取商品sku信息
  32. * 2021/08/20
  33. * GZ
  34. */
  35. func GetByUuid(site_id, dbname, uuid string, field string, url ...string) (map[string]string, error) {
  36. conn, err := rpc_server_conn(url...)
  37. if err != nil {
  38. return nil, err
  39. }
  40. defer conn.Close()
  41. req := &GetUuidRequest{proto.String(site_id), proto.String(dbname), proto.String(uuid), proto.String(field), nil}
  42. res := &GetResponse{}
  43. err = conn.GetByUuid(req, res)
  44. if err != nil {
  45. return nil, err
  46. }
  47. value := res.GetValue()
  48. var data map[string]string
  49. err = json.Unmarshal(value, &data)
  50. return data, err
  51. }