Browse Source

发布新版

master v0.1.4
listen 3 years ago
parent
commit
be8480c3dc
2 changed files with 24 additions and 11 deletions
  1. +11
    -11
      get_coupon.go
  2. +13
    -0
      get_coupon_test.go

+ 11
- 11
get_coupon.go View File

@ -5,16 +5,16 @@ import (
"errors"
)
func GetCouponInfo(dbname,couponId string, url ...string) (string, error) {
func GetCouponInfo(dbname,couponId string, url ...string) (map[string]string, error) {
if dbname == "" {
return "", errors.New("参数错误")
return nil, errors.New("参数错误")
}
conn, err := rpc_server_conn(url...)
if err != nil {
return "", err
return nil, err
}
defer conn.Close()
@ -25,31 +25,31 @@ func GetCouponInfo(dbname,couponId string, url ...string) (string, error) {
req, err := SetReqData(arg)
if err != nil {
return "", err
return nil, err
}
res := &CouponResponse{}
err = conn.GetCouponInfo(req, res)
if err != nil {
return "", err
return nil, err
}
res_data_de, err := GetResData(res)
if err != nil {
return "", err
return nil, err
}
var bankCode string
err = json.Unmarshal([]byte(res_data_de),&bankCode)
var couponInfo map[string]string
err = json.Unmarshal([]byte(res_data_de),&couponInfo)
if err != nil {
return "", err
return nil, err
}
if res_data_de == "" {
return "", nil
return nil, nil
}
return bankCode, nil
return couponInfo, nil
}

+ 13
- 0
get_coupon_test.go View File

@ -0,0 +1,13 @@
package couponrpc
import "testing"
func Test_getCoupon(t *testing.T) {
dbname := "shop_v2"
couponId := "4"
res, err := GetCouponInfo(dbname, couponId)
t.Log(res)
t.Log(err)
}

Loading…
Cancel
Save