Browse Source

增加sku查询方法

master v0.2.1
guzeng 3 years ago
parent
commit
9b2f51de66
2 changed files with 89 additions and 0 deletions
  1. +74
    -0
      getskuinfo.go
  2. +15
    -0
      getskuinfo_test.go

+ 74
- 0
getskuinfo.go View File

@ -0,0 +1,74 @@
package productrpc
import (
"encoding/json"
// "strconv"
// "time"
"github.com/golang/protobuf/proto"
)
/**
* id获取商品sku信息
* 2021/08/20
* GZ
*/
func GetSku(dbname, id string, url ...string) (map[string]string, error) {
conn, err := rpc_server_conn(url...)
if err != nil {
return nil, err
}
defer conn.Close()
req := &GetRequest{proto.String(dbname), proto.String(id), nil}
res := &GetResponse{}
err = conn.GetSku(req, res)
if err != nil {
return nil, err
}
value := res.GetValue()
var data map[string]string
err = json.Unmarshal(value, &data)
return data, err
}
/**
* uuid获取商品sku信息
* 2021/08/20
* GZ
*/
func GetSkuByUuid(dbname, uuid string, url ...string) (map[string]string, error) {
conn, err := rpc_server_conn(url...)
if err != nil {
return nil, err
}
defer conn.Close()
req := &GetUuidRequest{proto.String(dbname), proto.String(uuid), nil}
res := &GetResponse{}
err = conn.GetSkuByUuid(req, res)
if err != nil {
return nil, err
}
value := res.GetValue()
var data map[string]string
err = json.Unmarshal(value, &data)
return data, err
}

+ 15
- 0
getskuinfo_test.go View File

@ -0,0 +1,15 @@
package productrpc
import (
"testing"
)
func Test_GetSku(t *testing.T) {
dbname := "shop_v2"
id := "10"
ret, err := GetSku(dbname, id)
t.Log(ret)
t.Log(err)
}

Loading…
Cancel
Save