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

41 lines
601 B

  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(dbname, id 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(dbname), proto.String(id), 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. }