事务异常处理

master
shenzhuan 2 years ago
parent 1c8cf7bc0a
commit af403e050f

@ -5,10 +5,13 @@ import (
"fmt"
"github.com/afex/hystrix-go/hystrix"
consul "github.com/asim/go-micro/plugins/registry/consul/v4"
"github.com/dtm-labs/dtm/client/dtmcli"
"github.com/go-micro/plugins/v4/wrapper/select/roundrobin"
opentracing2 "github.com/go-micro/plugins/v4/wrapper/trace/opentracing"
"github.com/lithammer/shortuuid/v3"
"github.com/opentracing/opentracing-go"
"go-micro.dev/v4/client"
"go-micro.dev/v4/errors"
"go-micro.dev/v4/web"
"goproduct/common"
"goproduct/proto"
@ -24,6 +27,15 @@ import (
// 获取远程服务的客户端
func main() {
const (
//DTM 服务地址
DtmServer = "http://192.168.100.131:36789/api/dtmsvr"
QSBusi = "http://192.168.1.135:6668" //注意
)
var CartId int32 = 1
var Number int32 = 1
resp := &proto.AddCartResp{}
router := gin.Default()
//注册到consul
@ -57,7 +69,8 @@ func main() {
//负载均衡
micro.WrapClient(roundrobin.NewClientWrapper()),
)
client := proto.NewAddCartService("shop-cart", rpcServer.Client())
AddCartClient := proto.NewAddCartService("shop-cart", rpcServer.Client())
UpdateCartClient := proto.NewUpdateCartService("shop-cart", rpcServer.Client())
ShowProductDetailClient := proto.NewShowProductDetailService("shop-product", rpcServer.Client())
ShowDetailSkuClient := proto.NewShowDetailSkuService("shop-product", rpcServer.Client())
GetUserTokenClient := proto.NewGetUserTokenService("shop-user", rpcServer.Client())
@ -139,7 +152,7 @@ func main() {
}
log.Println(" /UpdateSkuClient resp :", respUpdate.IsSuccess)
//开始增加购物车
resp, err = client.AddCart(context.TODO(), req)
resp, err = AddCartClient.AddCart(context.TODO(), req)
//根据响应做输出
if err != nil {
log.Println("addCart err ", err)
@ -156,6 +169,153 @@ func main() {
common.RespOK(c.Writer, resp, "请求成功")
})
//开始拆分 DTM服务
//
router.POST("/updateSku", func(c *gin.Context) {
req := &proto.UpdateSkuReq{}
if err := c.BindJSON(req); err != nil {
log.Fatalln(err)
}
_, err := UpdateSkuClient.UpdateSku(context.TODO(), req)
if err != nil {
log.Println("/updateSku err ", err)
c.JSON(http.StatusOK, gin.H{"dtm_reslut": "FAILURE", "Message": "修改库存失败!"})
return
}
c.JSON(http.StatusOK, gin.H{"updateSku": "SUCCESS", "Message": "修改库存成功!"})
})
router.POST("/updateSku-compensate", func(c *gin.Context) {
req := &proto.UpdateSkuReq{}
if err := c.BindJSON(req); err != nil {
log.Fatalln(err)
}
req.ProductSku.Stock += Number
_, err := UpdateSkuClient.UpdateSku(context.TODO(), req)
if err != nil {
log.Println("/updateSku err ", err)
c.JSON(http.StatusOK, gin.H{"dtm_reslut": "FAILURE", "Message": "回滚库存失败!"})
return
}
c.JSON(http.StatusOK, gin.H{"updateSku-compensate": "SUCCESS", "Message": "回滚库存成功!"})
})
router.POST("/addCart", func(c *gin.Context) {
req := &proto.AddCartReq{}
if err := c.BindJSON(req); err != nil {
log.Fatalln(err)
}
resp, err = AddCartClient.AddCart(context.TODO(), req)
CartId = resp.ID
err = errors.New("400", "测试异常", 400)
if err != nil {
log.Println("/addCart err ", err)
c.JSON(http.StatusOK, gin.H{"dtm_reslut": "FAILURE", "Message": "新增购物车失败!"})
return
}
c.JSON(http.StatusOK, gin.H{"addCart": "SUCCESS", "Message": "新增购物车成功!"})
})
router.POST("/addCart-compensate", func(c *gin.Context) {
req := &proto.AddCartReq{}
if err := c.BindJSON(req); err != nil {
log.Fatalln(err)
}
req.Id = CartId
resp, err = UpdateCartClient.UpdateCart(context.TODO(), req)
CartId = resp.ID
if err != nil {
log.Println("/addCart-compensate err ", err)
c.JSON(http.StatusOK, gin.H{"dtm_reslut": "FAILURE", "Message": "删除购物车失败!"})
return
}
c.JSON(http.StatusOK, gin.H{"addCart-compensate": "SUCCESS", "Message": "删除购物车成功!"})
})
router.GET("/addShoppingCart", func(c *gin.Context) {
number, _ := strconv.Atoi(c.Request.FormValue("number"))
productId, _ := strconv.Atoi(c.Request.FormValue("productId"))
productSkuId, _ := strconv.Atoi(c.Request.FormValue("productSkuId"))
uuid := c.Request.Header["Uuid"][0]
cc := common.GetInput(uuid)
out := common.SQ(cc)
sum := 0
for o := range out {
sum += o
}
//Token校验
//拼接请求信息
tokenReq := &proto.TokenReq{
Uuid: uuid,
}
//响应
tokenResp, err := GetUserTokenClient.GetUserToken(context.TODO(), tokenReq)
//拼接请求信息
respErr := &proto.AddCartResp{}
if err != nil || tokenResp.IsLogin == false {
log.Println("GetUserToken err : ", err)
common.RespFail(c.Writer, respErr, "未登录!")
return
}
log.Println("GetUserToken success : ", tokenResp)
//拼接请求信息
req := &proto.AddCartReq{
Number: int32(number),
ProductId: int32(productId),
ProductSkuId: int32(productSkuId),
UserId: int32(sum),
}
resp := &proto.AddCartResp{}
//商品详情
reqDetail := &proto.ProductDetailReq{
Id: int32(productId),
}
respDetail, err := ShowProductDetailClient.ShowProductDetail(context.TODO(), reqDetail)
if err != nil {
log.Println("ShowProductDetail err : ", err)
common.RespFail(c.Writer, respErr, "查询商品详情失败!")
return
}
if respDetail != nil {
req.ProductName = respDetail.ProductDetail[0].Name
req.ProductMainPicture = respDetail.ProductDetail[0].MainPicture
}
//log.Println(" /ShowProductDetail resp :", respDetail)
//SKU详情
reqDetail.Id = req.ProductSkuId
respSkuDetail, err := ShowDetailSkuClient.ShowDetailSku(context.TODO(), reqDetail)
//log.Println(" /ShowDetailSku resp :", respSkuDetail)
//添加购物车 远程调用服务
//log.Println(" /AddCart req :", req)
if respSkuDetail.ProductSku[0].Stock < req.Number {
common.RespFail(c.Writer, &proto.AddCartResp{}, "库存不足,添加失败")
return
}
sku := respSkuDetail.ProductSku[0]
sku.Stock -= req.Number
Number = req.Number //
updateSkuReq := &proto.UpdateSkuReq{
ProductSku: sku,
}
resp.ProductSkuSimple = respSkuDetail.ProductSku[0]
resp.ProductSimple = respDetail.ProductDetail[0]
//全局事务
gid := shortuuid.New()
saga := dtmcli.NewSaga(DtmServer, gid).
Add(QSBusi+"/updateSku", QSBusi+"/updateSku-compensate", updateSkuReq).
Add(QSBusi+"/addCart", QSBusi+"/addCart-compensate", req)
err = saga.Submit()
if err != nil {
log.Println("saga submit err :", err)
common.RespFail(c.Writer, resp, "添加失败")
}
log.Println(" /saga submit submit :", gid)
////writer data message row total field
common.RespOK(c.Writer, resp, "请求成功")
})
service := web.NewService(
web.Address(":6668"),
web.Name("shop-cart-client"),

@ -18,6 +18,7 @@ import (
//接口
type ICartRepository interface {
AddCart(*proto.AddCartReq) (*model.ShoppingCart, error)
UpdateCart(*proto.AddCartReq) (*model.ShoppingCart, error)
}
// 创建实例
@ -45,3 +46,20 @@ func (u *CartRepository) AddCart(req *proto.AddCartReq) (obj *model.ShoppingCart
fmt.Println("repository AddCart >>>> ", cart)
return &cart, tb.Error //err
}
func (u *CartRepository) UpdateCart(req *proto.AddCartReq) (obj *model.ShoppingCart, err error) {
cart := model.ShoppingCart{
Number: req.Number,
ProductId: req.ProductId,
ProductSkuId: req.ProductSkuId,
ProductName: req.ProductName,
ProductMainPicture: req.ProductMainPicture,
UserId: req.UserId,
ID: req.Id,
}
cart.UpdateTime = time.Now() //
tb := u.mysqlDB.Model(&model.ShoppingCart{}).Where("id = ?", cart.ID).Update("is_deleted", 1)
//err = errors.New("400", "测试异常", 400)
fmt.Println("repository UpdateCart >>>> ", cart)
return &cart, tb.Error //err
}

@ -8,6 +8,7 @@ import (
type ICartService interface {
AddCart(*proto.AddCartReq) (obj *model.ShoppingCart, err error)
UpdateCart(*proto.AddCartReq) (obj *model.ShoppingCart, err error)
}
type CartService struct {
cartRepository repository.ICartRepository
@ -26,3 +27,6 @@ func NewCartService(cartRepository repository.ICartRepository) ICartService {
func (u *CartService) AddCart(req *proto.AddCartReq) (obj *model.ShoppingCart, err error) {
return u.cartRepository.AddCart(req)
}
func (u *CartService) UpdateCart(req *proto.AddCartReq) (obj *model.ShoppingCart, err error) {
return u.cartRepository.UpdateCart(req)
}

@ -23,13 +23,15 @@ require (
require (
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
github.com/asim/go-micro/plugins/registry/consul/v4 v4.7.0
github.com/dtm-labs/dtm v1.16.3
github.com/gin-gonic/gin v1.8.1
github.com/go-micro/plugins/v4/wrapper/ratelimiter/uber v1.1.0
github.com/go-micro/plugins/v4/wrapper/select/roundrobin v1.1.0
github.com/go-micro/plugins/v4/wrapper/trace/opentracing v1.1.0
github.com/lithammer/shortuuid/v3 v3.0.7
github.com/opentracing/opentracing-go v1.2.0
github.com/spf13/viper v1.12.0
github.com/uber/jaeger-client-go v2.30.0+incompatible
google.golang.org/grpc v1.49.0
gorm.io/driver/mysql v1.3.5
)
@ -37,31 +39,36 @@ require (
cloud.google.com/go v0.100.2 // indirect
cloud.google.com/go/compute v1.6.1 // indirect
cloud.google.com/go/firestore v1.6.1 // indirect
github.com/HdrHistogram/hdrhistogram-go v1.1.2 // indirect
github.com/Microsoft/go-winio v0.5.0 // indirect
github.com/Microsoft/go-winio v0.5.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect
github.com/acomagu/bufpipe v1.0.3 // indirect
github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 // indirect
github.com/armon/go-metrics v0.3.10 // indirect
github.com/bitly/go-simplejson v0.5.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/dtm-labs/dtmdriver v0.0.6 // indirect
github.com/dtm-labs/logger v0.0.1 // indirect
github.com/emirpasic/gods v1.12.0 // indirect
github.com/evanphx/json-patch/v5 v5.5.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/felixge/httpsnoop v1.0.1 // indirect
github.com/felixge/httpsnoop v1.0.2 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-acme/lego/v4 v4.4.0 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-git/go-billy/v5 v5.3.1 // indirect
github.com/go-git/go-git/v5 v5.4.2 // indirect
github.com/go-micro/plugins/v4/wrapper/select/roundrobin v1.1.0 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.10.0 // indirect
github.com/go-playground/validator/v10 v10.11.0 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/go-resty/resty/v2 v2.7.0 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/gobwas/httphead v0.1.0 // indirect
github.com/gobwas/pool v0.2.1 // indirect
github.com/gobwas/ws v1.0.4 // indirect
@ -69,6 +76,7 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/googleapis/gax-go/v2 v2.4.0 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
@ -84,6 +92,7 @@ require (
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
github.com/klauspost/compress v1.14.4 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
@ -93,16 +102,16 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/pelletier/go-toml/v2 v2.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/russross/blackfriday/v2 v2.0.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/crypt v0.6.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
@ -112,24 +121,30 @@ require (
github.com/ugorji/go/codec v1.2.7 // indirect
github.com/urfave/cli/v2 v2.3.0 // indirect
github.com/xanzy/ssh-agent v0.3.0 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.0.2 // indirect
github.com/xdg-go/stringprep v1.0.2 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
go.etcd.io/etcd/api/v3 v3.5.4 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.4 // indirect
go.etcd.io/etcd/client/v2 v2.305.4 // indirect
go.etcd.io/etcd/client/v3 v3.5.4 // indirect
go.mongodb.org/mongo-driver v1.9.1 // indirect
go.opencensus.io v0.23.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/ratelimit v0.2.0 // indirect
go.uber.org/zap v1.17.0 // indirect
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect
google.golang.org/api v0.81.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
google.golang.org/genproto v0.0.0-20220622171453-ea41d75dfa0f // indirect
google.golang.org/grpc v1.49.0 // indirect
gopkg.in/ini.v1 v1.66.6 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect

File diff suppressed because it is too large Load Diff

@ -11,24 +11,33 @@ type CartHandler struct {
CartService service.ICartService
}
// 查询商品列表
// 新增购物车
func (u *CartHandler) AddCart(ctx context.Context, req *proto.AddCartReq, resp *proto.AddCartResp) error {
// "number": 0,
// "productId": 0,
// "productSkuId": 0
//obj, err := u.CartService.AddCart(req.GetNumber(), req.GetProductId(), req.GetProductSkuId())
obj, err := u.CartService.AddCart(req)
if err != nil {
println(" AddCart err :", err)
} else {
//count = u.ProductDataService.CountNum()
//fmt.Println(">>>>>>>>>>>>> page product success :", obj)
//cart := &proto.ShoppingCart{}
//err1 := common.SwapToStruct(obj, resp)
resp.CanSetShoppingCartNumber = int64(obj.Number)
resp.ShoppingCartNumber = int64(obj.Number)
resp.IsBeyondMaxLimit = false // 查询sku
fmt.Println(" increase handler >>>>>> ", resp)
resp.ID = obj.ID //增加新增cart的ID
fmt.Println(" AddCart handler >>>>>> ", resp)
}
return err
}
//修改购物车
func (u *CartHandler) UpdateCart(ctx context.Context, req *proto.AddCartReq, resp *proto.AddCartResp) error {
obj, err := u.CartService.UpdateCart(req)
if err != nil {
println(" UpdateCart err :", err)
} else {
resp.CanSetShoppingCartNumber = int64(obj.Number)
resp.ShoppingCartNumber = int64(obj.Number)
resp.IsBeyondMaxLimit = false // 查询sku
resp.ID = obj.ID //增加新增cart的ID
fmt.Println(" UpdateCart handler >>>>>> ", resp)
}
return err
}

@ -60,6 +60,8 @@ func main() {
cartService := service.NewCartService(repository.NewCartRepository(db))
//4.注册handler
proto.RegisterAddCartHandler(repcService.Server(), &handler.CartHandler{cartService})
//4.注册handler
proto.RegisterUpdateCartHandler(repcService.Server(), &handler.CartHandler{cartService})
//5.启动服务
if err := repcService.Run(); err != nil {

@ -143,6 +143,7 @@ type AddCartReq struct {
ProductName string `protobuf:"bytes,4,opt,name=productName,proto3" json:"productName,omitempty"`
ProductMainPicture string `protobuf:"bytes,5,opt,name=productMainPicture,proto3" json:"productMainPicture,omitempty"`
UserId int32 `protobuf:"varint,6,opt,name=userId,proto3" json:"userId,omitempty"`
Id int32 `protobuf:"varint,7,opt,name=id,proto3" json:"id,omitempty"`
}
func (x *AddCartReq) Reset() {
@ -219,6 +220,13 @@ func (x *AddCartReq) GetUserId() int32 {
return 0
}
func (x *AddCartReq) GetId() int32 {
if x != nil {
return x.Id
}
return 0
}
// *
// "productSimple": {
// "id": 15,
@ -250,6 +258,7 @@ type AddCartResp struct {
ShoppingCartNumber int64 `protobuf:"varint,3,opt,name=shoppingCartNumber,proto3" json:"shoppingCartNumber,omitempty"`
CanSetShoppingCartNumber int64 `protobuf:"varint,4,opt,name=canSetShoppingCartNumber,proto3" json:"canSetShoppingCartNumber,omitempty"`
IsBeyondMaxLimit bool `protobuf:"varint,5,opt,name=isBeyondMaxLimit,proto3" json:"isBeyondMaxLimit,omitempty"`
ID int32 `protobuf:"varint,6,opt,name=ID,proto3" json:"ID,omitempty"`
}
func (x *AddCartResp) Reset() {
@ -319,6 +328,13 @@ func (x *AddCartResp) GetIsBeyondMaxLimit() bool {
return false
}
func (x *AddCartResp) GetID() int32 {
if x != nil {
return x.ID
}
return 0
}
type Product struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -1245,7 +1261,7 @@ var file_cart_proto_rawDesc = []byte{
0x69, 0x63, 0x74, 0x75, 0x72, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x12, 0x70, 0x72,
0x6f, 0x64, 0x75, 0x63, 0x74, 0x4d, 0x61, 0x69, 0x6e, 0x50, 0x69, 0x63, 0x74, 0x75, 0x72, 0x65,
0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x07, 0x20, 0x01, 0x28, 0x05,
0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0xd0, 0x01, 0x0a, 0x0a, 0x41, 0x64, 0x64,
0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0xe0, 0x01, 0x0a, 0x0a, 0x41, 0x64, 0x64,
0x43, 0x61, 0x72, 0x74, 0x52, 0x65, 0x71, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65,
0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12,
0x1c, 0x0a, 0x09, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01,
@ -1258,7 +1274,8 @@ var file_cart_proto_rawDesc = []byte{
0x69, 0x6e, 0x50, 0x69, 0x63, 0x74, 0x75, 0x72, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52,
0x12, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x4d, 0x61, 0x69, 0x6e, 0x50, 0x69, 0x63, 0x74,
0x75, 0x72, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x06, 0x20,
0x01, 0x28, 0x05, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22, 0xa0, 0x02, 0x0a, 0x0b,
0x01, 0x28, 0x05, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x69,
0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x69, 0x64, 0x22, 0xb0, 0x02, 0x0a, 0x0b,
0x41, 0x64, 0x64, 0x43, 0x61, 0x72, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x3a, 0x0a, 0x0d, 0x70,
0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x53, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01,
0x28, 0x0b, 0x32, 0x14, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75,
@ -1276,7 +1293,8 @@ var file_cart_proto_rawDesc = []byte{
0x53, 0x68, 0x6f, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x43, 0x61, 0x72, 0x74, 0x4e, 0x75, 0x6d, 0x62,
0x65, 0x72, 0x12, 0x2a, 0x0a, 0x10, 0x69, 0x73, 0x42, 0x65, 0x79, 0x6f, 0x6e, 0x64, 0x4d, 0x61,
0x78, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x10, 0x69, 0x73,
0x42, 0x65, 0x79, 0x6f, 0x6e, 0x64, 0x4d, 0x61, 0x78, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x22, 0xec,
0x42, 0x65, 0x79, 0x6f, 0x6e, 0x64, 0x4d, 0x61, 0x78, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x0e,
0x0a, 0x02, 0x49, 0x44, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x49, 0x44, 0x22, 0xec,
0x02, 0x0a, 0x07, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64,
0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61,
0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x24,
@ -1387,36 +1405,41 @@ var file_cart_proto_rawDesc = []byte{
0x72, 0x74, 0x12, 0x32, 0x0a, 0x07, 0x41, 0x64, 0x64, 0x43, 0x61, 0x72, 0x74, 0x12, 0x11, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x41, 0x64, 0x64, 0x43, 0x61, 0x72, 0x74, 0x52, 0x65, 0x71,
0x1a, 0x12, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x41, 0x64, 0x64, 0x43, 0x61, 0x72, 0x74,
0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x32, 0x31, 0x0a, 0x04, 0x50, 0x61, 0x67, 0x65, 0x12, 0x29,
0x0a, 0x04, 0x50, 0x61, 0x67, 0x65, 0x12, 0x0e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50,
0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x1a, 0x0f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50,
0x61, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x32, 0x5d, 0x0a, 0x11, 0x53, 0x68, 0x6f,
0x77, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x12, 0x48,
0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x32, 0x43, 0x0a, 0x0a, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65,
0x43, 0x61, 0x72, 0x74, 0x12, 0x35, 0x0a, 0x0a, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x43, 0x61,
0x72, 0x74, 0x12, 0x11, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x41, 0x64, 0x64, 0x43, 0x61,
0x72, 0x74, 0x52, 0x65, 0x71, 0x1a, 0x12, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x41, 0x64,
0x64, 0x43, 0x61, 0x72, 0x74, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x32, 0x31, 0x0a, 0x04, 0x50,
0x61, 0x67, 0x65, 0x12, 0x29, 0x0a, 0x04, 0x50, 0x61, 0x67, 0x65, 0x12, 0x0e, 0x2e, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x1a, 0x0f, 0x2e, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x61, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x32, 0x5d,
0x0a, 0x11, 0x53, 0x68, 0x6f, 0x77, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x44, 0x65, 0x74,
0x61, 0x69, 0x6c, 0x12, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x72, 0x6f, 0x64,
0x75, 0x63, 0x74, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x71, 0x1a, 0x18, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x44, 0x65, 0x74, 0x61,
0x69, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x32, 0x51, 0x0a, 0x0e, 0x53, 0x68, 0x6f, 0x77,
0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x53, 0x6b, 0x75, 0x12, 0x3f, 0x0a, 0x0e, 0x53, 0x68,
0x6f, 0x77, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x53, 0x6b, 0x75, 0x12, 0x14, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x53, 0x6b, 0x75, 0x52,
0x65, 0x71, 0x1a, 0x15, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75,
0x63, 0x74, 0x53, 0x6b, 0x75, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x32, 0x52, 0x0a, 0x0d, 0x53,
0x68, 0x6f, 0x77, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x53, 0x6b, 0x75, 0x12, 0x41, 0x0a, 0x0d,
0x53, 0x68, 0x6f, 0x77, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x53, 0x6b, 0x75, 0x12, 0x17, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x44, 0x65, 0x74,
0x61, 0x69, 0x6c, 0x52, 0x65, 0x71, 0x1a, 0x15, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50,
0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x53, 0x6b, 0x75, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x32,
0x43, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12,
0x33, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12,
0x0f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x71,
0x1a, 0x10, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65,
0x73, 0x70, 0x22, 0x00, 0x32, 0x45, 0x0a, 0x09, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x53, 0x6b,
0x75, 0x12, 0x38, 0x0a, 0x09, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x53, 0x6b, 0x75, 0x12, 0x13,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x53, 0x6b, 0x75,
0x52, 0x65, 0x71, 0x1a, 0x14, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x55, 0x70, 0x64, 0x61,
0x74, 0x65, 0x53, 0x6b, 0x75, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x42, 0x0a, 0x5a, 0x08, 0x2e,
0x2f, 0x3b, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x61, 0x69, 0x6c, 0x12, 0x48, 0x0a, 0x11, 0x53, 0x68, 0x6f, 0x77, 0x50, 0x72, 0x6f, 0x64, 0x75,
0x63, 0x74, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x12, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x52, 0x65,
0x71, 0x1a, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63,
0x74, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x32, 0x51, 0x0a,
0x0e, 0x53, 0x68, 0x6f, 0x77, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x53, 0x6b, 0x75, 0x12,
0x3f, 0x0a, 0x0e, 0x53, 0x68, 0x6f, 0x77, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x53, 0x6b,
0x75, 0x12, 0x14, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63,
0x74, 0x53, 0x6b, 0x75, 0x52, 0x65, 0x71, 0x1a, 0x15, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e,
0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x53, 0x6b, 0x75, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00,
0x32, 0x52, 0x0a, 0x0d, 0x53, 0x68, 0x6f, 0x77, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x53, 0x6b,
0x75, 0x12, 0x41, 0x0a, 0x0d, 0x53, 0x68, 0x6f, 0x77, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x53,
0x6b, 0x75, 0x12, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75,
0x63, 0x74, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x71, 0x1a, 0x15, 0x2e, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x53, 0x6b, 0x75, 0x52, 0x65,
0x73, 0x70, 0x22, 0x00, 0x32, 0x43, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x54,
0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x33, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x54,
0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x0f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x54, 0x6f, 0x6b,
0x65, 0x6e, 0x52, 0x65, 0x71, 0x1a, 0x10, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x54, 0x6f,
0x6b, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x32, 0x45, 0x0a, 0x09, 0x55, 0x70, 0x64,
0x61, 0x74, 0x65, 0x53, 0x6b, 0x75, 0x12, 0x38, 0x0a, 0x09, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65,
0x53, 0x6b, 0x75, 0x12, 0x13, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x55, 0x70, 0x64, 0x61,
0x74, 0x65, 0x53, 0x6b, 0x75, 0x52, 0x65, 0x71, 0x1a, 0x14, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x53, 0x6b, 0x75, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00,
0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2f, 0x3b, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -1460,21 +1483,23 @@ var file_cart_proto_depIdxs = []int32{
9, // 5: proto.ProductSkuResp.productSku:type_name -> proto.ProductSku
9, // 6: proto.UpdateSkuReq.productSku:type_name -> proto.ProductSku
1, // 7: proto.AddCart.AddCart:input_type -> proto.AddCartReq
4, // 8: proto.Page.Page:input_type -> proto.PageReq
7, // 9: proto.ShowProductDetail.ShowProductDetail:input_type -> proto.ProductDetailReq
10, // 10: proto.ShowProductSku.ShowProductSku:input_type -> proto.ProductSkuReq
7, // 11: proto.ShowDetailSku.ShowDetailSku:input_type -> proto.ProductDetailReq
12, // 12: proto.GetUserToken.GetUserToken:input_type -> proto.TokenReq
14, // 13: proto.UpdateSku.UpdateSku:input_type -> proto.UpdateSkuReq
2, // 14: proto.AddCart.AddCart:output_type -> proto.AddCartResp
5, // 15: proto.Page.Page:output_type -> proto.PageResp
8, // 16: proto.ShowProductDetail.ShowProductDetail:output_type -> proto.ProductDetailResp
11, // 17: proto.ShowProductSku.ShowProductSku:output_type -> proto.ProductSkuResp
11, // 18: proto.ShowDetailSku.ShowDetailSku:output_type -> proto.ProductSkuResp
13, // 19: proto.GetUserToken.GetUserToken:output_type -> proto.TokenResp
15, // 20: proto.UpdateSku.UpdateSku:output_type -> proto.UpdateSkuResp
14, // [14:21] is the sub-list for method output_type
7, // [7:14] is the sub-list for method input_type
1, // 8: proto.UpdateCart.UpdateCart:input_type -> proto.AddCartReq
4, // 9: proto.Page.Page:input_type -> proto.PageReq
7, // 10: proto.ShowProductDetail.ShowProductDetail:input_type -> proto.ProductDetailReq
10, // 11: proto.ShowProductSku.ShowProductSku:input_type -> proto.ProductSkuReq
7, // 12: proto.ShowDetailSku.ShowDetailSku:input_type -> proto.ProductDetailReq
12, // 13: proto.GetUserToken.GetUserToken:input_type -> proto.TokenReq
14, // 14: proto.UpdateSku.UpdateSku:input_type -> proto.UpdateSkuReq
2, // 15: proto.AddCart.AddCart:output_type -> proto.AddCartResp
2, // 16: proto.UpdateCart.UpdateCart:output_type -> proto.AddCartResp
5, // 17: proto.Page.Page:output_type -> proto.PageResp
8, // 18: proto.ShowProductDetail.ShowProductDetail:output_type -> proto.ProductDetailResp
11, // 19: proto.ShowProductSku.ShowProductSku:output_type -> proto.ProductSkuResp
11, // 20: proto.ShowDetailSku.ShowDetailSku:output_type -> proto.ProductSkuResp
13, // 21: proto.GetUserToken.GetUserToken:output_type -> proto.TokenResp
15, // 22: proto.UpdateSku.UpdateSku:output_type -> proto.UpdateSkuResp
15, // [15:23] is the sub-list for method output_type
7, // [7:15] is the sub-list for method input_type
7, // [7:7] is the sub-list for extension type_name
7, // [7:7] is the sub-list for extension extendee
0, // [0:7] is the sub-list for field type_name
@ -1687,7 +1712,7 @@ func file_cart_proto_init() {
NumEnums: 0,
NumMessages: 17,
NumExtensions: 0,
NumServices: 7,
NumServices: 8,
},
GoTypes: file_cart_proto_goTypes,
DependencyIndexes: file_cart_proto_depIdxs,

@ -88,6 +88,67 @@ func (h *addCartHandler) AddCart(ctx context.Context, in *AddCartReq, out *AddCa
return h.AddCartHandler.AddCart(ctx, in, out)
}
// Api Endpoints for UpdateCart service
func NewUpdateCartEndpoints() []*api.Endpoint {
return []*api.Endpoint{}
}
// Client API for UpdateCart service
type UpdateCartService interface {
// rpc 服务
UpdateCart(ctx context.Context, in *AddCartReq, opts ...client.CallOption) (*AddCartResp, error)
}
type updateCartService struct {
c client.Client
name string
}
func NewUpdateCartService(name string, c client.Client) UpdateCartService {
return &updateCartService{
c: c,
name: name,
}
}
func (c *updateCartService) UpdateCart(ctx context.Context, in *AddCartReq, opts ...client.CallOption) (*AddCartResp, error) {
req := c.c.NewRequest(c.name, "UpdateCart.UpdateCart", in)
out := new(AddCartResp)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for UpdateCart service
type UpdateCartHandler interface {
// rpc 服务
UpdateCart(context.Context, *AddCartReq, *AddCartResp) error
}
func RegisterUpdateCartHandler(s server.Server, hdlr UpdateCartHandler, opts ...server.HandlerOption) error {
type updateCart interface {
UpdateCart(ctx context.Context, in *AddCartReq, out *AddCartResp) error
}
type UpdateCart struct {
updateCart
}
h := &updateCartHandler{hdlr}
return s.Handle(s.NewHandler(&UpdateCart{h}, opts...))
}
type updateCartHandler struct {
UpdateCartHandler
}
func (h *updateCartHandler) UpdateCart(ctx context.Context, in *AddCartReq, out *AddCartResp) error {
return h.UpdateCartHandler.UpdateCart(ctx, in, out)
}
// Api Endpoints for Page service
func NewPageEndpoints() []*api.Endpoint {

@ -47,6 +47,7 @@ message AddCartReq {
string productName = 4;
string productMainPicture = 5;
int32 userId =6;
int32 id = 7;
}
// resp struct
/**
@ -77,12 +78,20 @@ message AddCartResp{
int64 shoppingCartNumber = 3;
int64 canSetShoppingCartNumber = 4;
bool isBeyondMaxLimit = 5;
int32 ID = 6;
}
//RPC
service AddCart {
//rpc
rpc AddCart (AddCartReq) returns (AddCartResp){}
}
service UpdateCart {
//rpc
rpc UpdateCart (AddCartReq) returns (AddCartResp){}
}
message Product {
int32 id = 1;
string name = 2;

Loading…
Cancel
Save