parent
555f9e86e0
commit
66e4c2de0c
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="Go" enabled="true">
|
||||
<buildTags>
|
||||
<option name="goVersion" value="go1.17" />
|
||||
</buildTags>
|
||||
</component>
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectTasksOptions">
|
||||
<enabled-global>
|
||||
<option value="go fmt" />
|
||||
</enabled-global>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,351 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"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/web"
|
||||
//"goproduct/common"
|
||||
common "git.mashibing.com/msb_47094/shopping-comm"
|
||||
"goproduct/proto"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-micro.dev/v4"
|
||||
"go-micro.dev/v4/registry"
|
||||
)
|
||||
|
||||
// 获取远程服务的客户端
|
||||
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
|
||||
consulReg := consul.NewRegistry(func(options *registry.Options) {
|
||||
options.Addrs = []string{"192.168.100.131:8500"}
|
||||
})
|
||||
//初始化链路追踪的jaeper
|
||||
t, io, err := common.NewTracer("shop-cart-client", "192.168.100.131:6831")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
defer io.Close()
|
||||
opentracing.SetGlobalTracer(t)
|
||||
|
||||
//熔断器
|
||||
hystrixStreamHandler := hystrix.NewStreamHandler()
|
||||
hystrixStreamHandler.Start()
|
||||
go func() {
|
||||
err := http.ListenAndServe(net.JoinHostPort("192.168.100.1", "9096"), hystrixStreamHandler)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
}()
|
||||
|
||||
rpcServer := micro.NewService(
|
||||
//micro.Name("shop-product-client"),
|
||||
micro.Registry(consulReg), //服务发现
|
||||
micro.WrapClient(opentracing2.NewClientWrapper(opentracing.GlobalTracer())),
|
||||
//加入熔断器
|
||||
micro.WrapClient(NewClientHystrixWrapper()),
|
||||
//负载均衡
|
||||
micro.WrapClient(roundrobin.NewClientWrapper()),
|
||||
)
|
||||
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())
|
||||
UpdateSkuClient := proto.NewUpdateSkuService("shop-product", rpcServer.Client())
|
||||
|
||||
//添加购物车
|
||||
router.GET("/increase", 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
|
||||
updateSkuReq := &proto.UpdateSkuReq{
|
||||
ProductSku: sku,
|
||||
}
|
||||
respUpdate, err := UpdateSkuClient.UpdateSku(context.TODO(), updateSkuReq)
|
||||
if err != nil {
|
||||
log.Println(" /UpdateSku err :", err)
|
||||
common.RespFail(c.Writer, resp, "修改库存失败!")
|
||||
return
|
||||
}
|
||||
log.Println(" /UpdateSkuClient resp :", respUpdate.IsSuccess)
|
||||
//开始增加购物车
|
||||
resp, err = AddCartClient.AddCart(context.TODO(), req)
|
||||
//根据响应做输出
|
||||
if err != nil {
|
||||
log.Println("addCart err ", err)
|
||||
updateSkuReq.ProductSku.Stock += req.Number
|
||||
_, err = UpdateSkuClient.UpdateSku(context.TODO(), updateSkuReq)
|
||||
log.Println("rollback sku is Err :", err)
|
||||
common.RespFail(c.Writer, resp, "添加购物车失败!")
|
||||
return
|
||||
}
|
||||
resp.ProductSkuSimple = respSkuDetail.ProductSku[0]
|
||||
resp.ProductSimple = respDetail.ProductDetail[0]
|
||||
log.Println(" /AddCart resp :", resp)
|
||||
////writer data message row total field
|
||||
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"),
|
||||
web.Registry(consulReg),
|
||||
web.Handler(router),
|
||||
)
|
||||
//启动服务
|
||||
service.Run()
|
||||
}
|
||||
|
||||
type clientWrapper struct {
|
||||
client.Client
|
||||
}
|
||||
|
||||
func (c clientWrapper) Call(ctx context.Context, req client.Request, resp interface{}, opts ...client.CallOption) error {
|
||||
return hystrix.Do(req.Service()+"."+req.Endpoint(), func() error {
|
||||
//正常执行
|
||||
fmt.Println("call success ", req.Service()+"."+req.Endpoint())
|
||||
return c.Client.Call(ctx, req, resp, opts...)
|
||||
}, func(err error) error {
|
||||
fmt.Println("call err :", err)
|
||||
return err
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func NewClientHystrixWrapper() client.Wrapper {
|
||||
return func(i client.Client) client.Client {
|
||||
return &clientWrapper{i}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
type TraderOrder struct {
|
||||
//gorm.Model
|
||||
ID int32 `json:"id"`
|
||||
OrderNo string `json:"orderNo"`
|
||||
UserId int32 `gorm:"default:1" json:"userId"`
|
||||
TotalAmount float32 `gorm:"total_amount" json:"totalAmount"`
|
||||
ShippingAmount float32 `gorm:"shipping_amount" json:"shippingAmount"`
|
||||
DiscountAmount float32 `gorm:"discount_amount" json:"discountAmount"`
|
||||
PayAmount float32 `gorm:"pay_amount" json:"payAmount"`
|
||||
RefundAmount float32 `gorm:"refund_amount" json:"refundAmount"`
|
||||
SubmitTime time.Time `json:"submitTime"`
|
||||
ExpireTime time.Time `json:"expireTime"`
|
||||
AutoReceiveTime time.Time `json:"autoReceiveTime"`
|
||||
ReceiveTime time.Time `json:"receiveTime"`
|
||||
AutoPraise time.Time `json:"autoPraise"`
|
||||
AfterSaleDeadlineTime time.Time `json:"afterSaleDeadlineTime"`
|
||||
OrderStatus int32 `gorm:"default:1" json:"orderStatus"`
|
||||
OrderSource int32 `gorm:"default:6" json:"orderSource"`
|
||||
CancelReason int32 `gorm:"cancel_reason" json:"cancelReason"`
|
||||
OrderType int32 `gorm:"default:1" json:"orderType"`
|
||||
CreateUser int32 `gorm:"default:1" json:"createUser"`
|
||||
CreateTime time.Time `json:"createTime"`
|
||||
UpdateUser int32 `json:"updateUser"`
|
||||
UpdateTime time.Time `json:"updateTime"`
|
||||
IsDeleted bool `json:"isDeleted"`
|
||||
}
|
||||
|
||||
func (table *TraderOrder) TableName() string {
|
||||
return "trade_order"
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"goproduct/domain/model"
|
||||
"goproduct/proto"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
/**
|
||||
int32 clientId = 1;
|
||||
string phone = 2;
|
||||
int32 systemId = 3;
|
||||
string verificationCode = 4;
|
||||
**/
|
||||
//接口
|
||||
type ICartRepository interface {
|
||||
AddCart(*proto.AddCartReq) (*model.ShoppingCart, error)
|
||||
UpdateCart(*proto.AddCartReq) (*model.ShoppingCart, error)
|
||||
}
|
||||
|
||||
// 创建实例
|
||||
func NewCartRepository(db *gorm.DB) ICartRepository {
|
||||
return &CartRepository{mysqlDB: db}
|
||||
}
|
||||
|
||||
// 数据DB
|
||||
type CartRepository struct {
|
||||
mysqlDB *gorm.DB
|
||||
}
|
||||
|
||||
func (u *CartRepository) AddCart(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,
|
||||
}
|
||||
cart.CreateTime = time.Now() //
|
||||
tb := u.mysqlDB.Create(&cart)
|
||||
//err = errors.New("400", "测试异常", 400)
|
||||
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
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"goproduct/domain/model"
|
||||
"goproduct/domain/repository"
|
||||
"goproduct/proto"
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func NewCartService(cartRepository repository.ICartRepository) ICartService {
|
||||
return &CartService{cartRepository: cartRepository}
|
||||
}
|
||||
|
||||
// "number": 0,
|
||||
//
|
||||
// "productId": 0,
|
||||
// "productSkuId": 0
|
||||
//
|
||||
// 重写接口方法
|
||||
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)
|
||||
}
|
@ -0,0 +1,152 @@
|
||||
module trade-order
|
||||
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
go-micro.dev/v4 v4.8.0
|
||||
google.golang.org/protobuf v1.28.0
|
||||
gorm.io/gorm v1.24.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/miekg/dns v1.1.50 // indirect
|
||||
golang.org/x/net v0.0.0-20220708220712-1185a9018129 // indirect
|
||||
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
|
||||
golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e // indirect
|
||||
golang.org/x/tools v0.1.11 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
git.mashibing.com/msb_47094/shopping-comm v0.0.0-20221031053804-df4c81cf5ca3
|
||||
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
|
||||
)
|
||||
|
||||
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/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.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.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-playground/locales v0.14.0 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.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
|
||||
github.com/goccy/go-json v0.9.7 // indirect
|
||||
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
|
||||
github.com/hashicorp/consul/api v1.12.0 // indirect
|
||||
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
||||
github.com/hashicorp/go-hclog v1.2.0 // indirect
|
||||
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
|
||||
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
|
||||
github.com/hashicorp/golang-lru v0.5.4 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/hashicorp/serf v0.9.7 // indirect
|
||||
github.com/imdario/mergo v0.3.12 // indirect
|
||||
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
|
||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||
github.com/mitchellh/hashstructure v1.1.0 // indirect
|
||||
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.5 // indirect
|
||||
github.com/pkg/errors v0.9.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.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
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/spf13/viper v1.13.0 // indirect
|
||||
github.com/subosito/gotenv v1.4.1 // indirect
|
||||
github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect
|
||||
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
|
||||
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.9.0 // indirect
|
||||
go.uber.org/multierr v1.8.0 // indirect
|
||||
go.uber.org/ratelimit v0.2.0 // 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-20220622171453-ea41d75dfa0f // indirect
|
||||
google.golang.org/grpc v1.49.0 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // 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
|
||||
gorm.io/driver/mysql v1.4.3 // indirect
|
||||
)
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,43 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"goproduct/domain/service"
|
||||
"goproduct/proto"
|
||||
)
|
||||
|
||||
type CartHandler struct {
|
||||
CartService service.ICartService
|
||||
}
|
||||
|
||||
// 新增购物车
|
||||
func (u *CartHandler) AddCart(ctx context.Context, req *proto.AddCartReq, resp *proto.AddCartResp) error {
|
||||
obj, err := u.CartService.AddCart(req)
|
||||
if err != nil {
|
||||
println(" AddCart 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(" 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
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
common "git.mashibing.com/msb_47094/shopping-comm"
|
||||
consul "github.com/asim/go-micro/plugins/registry/consul/v4"
|
||||
ratelimiter "github.com/go-micro/plugins/v4/wrapper/ratelimiter/uber"
|
||||
opentracing2 "github.com/go-micro/plugins/v4/wrapper/trace/opentracing"
|
||||
"github.com/opentracing/opentracing-go"
|
||||
"go-micro.dev/v4"
|
||||
"go-micro.dev/v4/registry"
|
||||
"goproduct/domain/repository"
|
||||
"goproduct/domain/service"
|
||||
"goproduct/handler"
|
||||
"goproduct/proto"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
consulStr = "http://192.168.100.131:8500"
|
||||
consulReistStr = "192.168.100.131:8500"
|
||||
fileKey = "mysql-product"
|
||||
QPS = 100
|
||||
)
|
||||
|
||||
func main() {
|
||||
//0 配置中心
|
||||
consulConfig, err := common.GetConsulConfig(consulStr, fileKey)
|
||||
if err != nil {
|
||||
log.Println("consulConfig err :", err)
|
||||
}
|
||||
// 1.consul注册中心
|
||||
consulReist := consul.NewRegistry(func(options *registry.Options) {
|
||||
options.Addrs = []string{consulReistStr}
|
||||
})
|
||||
//链路追踪实列化 注意addr是 jaeper地址 端口号6831
|
||||
t, io, err := common.NewTracer("shop-cart", "192.168.100.131:6831")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer io.Close()
|
||||
//设置全局的Tracing
|
||||
opentracing.SetGlobalTracer(t)
|
||||
|
||||
repcService := micro.NewService(
|
||||
micro.RegisterTTL(time.Second*30),
|
||||
micro.RegisterInterval(time.Second*30),
|
||||
micro.Name("shop-cart"),
|
||||
micro.Address(":8084"),
|
||||
micro.Version("v1"),
|
||||
micro.Registry(consulReist),
|
||||
//链路追踪
|
||||
micro.WrapHandler(opentracing2.NewHandlerWrapper(opentracing.GlobalTracer())),
|
||||
//server 限流
|
||||
micro.WrapHandler(ratelimiter.NewHandlerWrapper(QPS)),
|
||||
)
|
||||
//2.初始化db
|
||||
db, _ := common.GetMysqlFromConsul(consulConfig)
|
||||
//3.创建服务实例
|
||||
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 {
|
||||
log.Println("start cart service err :", err)
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,514 @@
|
||||
// Code generated by protoc-gen-micro. DO NOT EDIT.
|
||||
// source: trade.proto
|
||||
|
||||
package proto
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
proto "google.golang.org/protobuf/proto"
|
||||
math "math"
|
||||
)
|
||||
|
||||
import (
|
||||
context "context"
|
||||
api "go-micro.dev/v4/api"
|
||||
client "go-micro.dev/v4/client"
|
||||
server "go-micro.dev/v4/server"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ api.Endpoint
|
||||
var _ context.Context
|
||||
var _ client.Option
|
||||
var _ server.Option
|
||||
|
||||
// Api Endpoints for AddTraderOrder service
|
||||
|
||||
func NewAddTraderOrderEndpoints() []*api.Endpoint {
|
||||
return []*api.Endpoint{}
|
||||
}
|
||||
|
||||
// Client API for AddTraderOrder service
|
||||
|
||||
type AddTraderOrderService interface {
|
||||
// rpc 服务
|
||||
AddTraderOrder(ctx context.Context, in *AddTraderOrderReq, opts ...client.CallOption) (*AddTraderOrderResp, error)
|
||||
}
|
||||
|
||||
type addTraderOrderService struct {
|
||||
c client.Client
|
||||
name string
|
||||
}
|
||||
|
||||
func NewAddTraderOrderService(name string, c client.Client) AddTraderOrderService {
|
||||
return &addTraderOrderService{
|
||||
c: c,
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *addTraderOrderService) AddTraderOrder(ctx context.Context, in *AddTraderOrderReq, opts ...client.CallOption) (*AddTraderOrderResp, error) {
|
||||
req := c.c.NewRequest(c.name, "AddTraderOrder.AddTraderOrder", in)
|
||||
out := new(AddTraderOrderResp)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Server API for AddTraderOrder service
|
||||
|
||||
type AddTraderOrderHandler interface {
|
||||
// rpc 服务
|
||||
AddTraderOrder(context.Context, *AddTraderOrderReq, *AddTraderOrderResp) error
|
||||
}
|
||||
|
||||
func RegisterAddTraderOrderHandler(s server.Server, hdlr AddTraderOrderHandler, opts ...server.HandlerOption) error {
|
||||
type addTraderOrder interface {
|
||||
AddTraderOrder(ctx context.Context, in *AddTraderOrderReq, out *AddTraderOrderResp) error
|
||||
}
|
||||
type AddTraderOrder struct {
|
||||
addTraderOrder
|
||||
}
|
||||
h := &addTraderOrderHandler{hdlr}
|
||||
return s.Handle(s.NewHandler(&AddTraderOrder{h}, opts...))
|
||||
}
|
||||
|
||||
type addTraderOrderHandler struct {
|
||||
AddTraderOrderHandler
|
||||
}
|
||||
|
||||
func (h *addTraderOrderHandler) AddTraderOrder(ctx context.Context, in *AddTraderOrderReq, out *AddTraderOrderResp) error {
|
||||
return h.AddTraderOrderHandler.AddTraderOrder(ctx, in, out)
|
||||
}
|
||||
|
||||
// Api Endpoints for UpdateTraderOrder service
|
||||
|
||||
func NewUpdateTraderOrderEndpoints() []*api.Endpoint {
|
||||
return []*api.Endpoint{}
|
||||
}
|
||||
|
||||
// Client API for UpdateTraderOrder service
|
||||
|
||||
type UpdateTraderOrderService interface {
|
||||
// rpc 服务
|
||||
UpdateTraderOrder(ctx context.Context, in *AddTraderOrderReq, opts ...client.CallOption) (*AddTraderOrderResp, error)
|
||||
}
|
||||
|
||||
type updateTraderOrderService struct {
|
||||
c client.Client
|
||||
name string
|
||||
}
|
||||
|
||||
func NewUpdateTraderOrderService(name string, c client.Client) UpdateTraderOrderService {
|
||||
return &updateTraderOrderService{
|
||||
c: c,
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *updateTraderOrderService) UpdateTraderOrder(ctx context.Context, in *AddTraderOrderReq, opts ...client.CallOption) (*AddTraderOrderResp, error) {
|
||||
req := c.c.NewRequest(c.name, "UpdateTraderOrder.UpdateTraderOrder", in)
|
||||
out := new(AddTraderOrderResp)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Server API for UpdateTraderOrder service
|
||||
|
||||
type UpdateTraderOrderHandler interface {
|
||||
// rpc 服务
|
||||
UpdateTraderOrder(context.Context, *AddTraderOrderReq, *AddTraderOrderResp) error
|
||||
}
|
||||
|
||||
func RegisterUpdateTraderOrderHandler(s server.Server, hdlr UpdateTraderOrderHandler, opts ...server.HandlerOption) error {
|
||||
type updateTraderOrder interface {
|
||||
UpdateTraderOrder(ctx context.Context, in *AddTraderOrderReq, out *AddTraderOrderResp) error
|
||||
}
|
||||
type UpdateTraderOrder struct {
|
||||
updateTraderOrder
|
||||
}
|
||||
h := &updateTraderOrderHandler{hdlr}
|
||||
return s.Handle(s.NewHandler(&UpdateTraderOrder{h}, opts...))
|
||||
}
|
||||
|
||||
type updateTraderOrderHandler struct {
|
||||
UpdateTraderOrderHandler
|
||||
}
|
||||
|
||||
func (h *updateTraderOrderHandler) UpdateTraderOrder(ctx context.Context, in *AddTraderOrderReq, out *AddTraderOrderResp) error {
|
||||
return h.UpdateTraderOrderHandler.UpdateTraderOrder(ctx, in, out)
|
||||
}
|
||||
|
||||
// Api Endpoints for Page service
|
||||
|
||||
func NewPageEndpoints() []*api.Endpoint {
|
||||
return []*api.Endpoint{}
|
||||
}
|
||||
|
||||
// Client API for Page service
|
||||
|
||||
type PageService interface {
|
||||
// rpc 服务
|
||||
Page(ctx context.Context, in *PageReq, opts ...client.CallOption) (*PageResp, error)
|
||||
}
|
||||
|
||||
type pageService struct {
|
||||
c client.Client
|
||||
name string
|
||||
}
|
||||
|
||||
func NewPageService(name string, c client.Client) PageService {
|
||||
return &pageService{
|
||||
c: c,
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *pageService) Page(ctx context.Context, in *PageReq, opts ...client.CallOption) (*PageResp, error) {
|
||||
req := c.c.NewRequest(c.name, "Page.Page", in)
|
||||
out := new(PageResp)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Server API for Page service
|
||||
|
||||
type PageHandler interface {
|
||||
// rpc 服务
|
||||
Page(context.Context, *PageReq, *PageResp) error
|
||||
}
|
||||
|
||||
func RegisterPageHandler(s server.Server, hdlr PageHandler, opts ...server.HandlerOption) error {
|
||||
type page interface {
|
||||
Page(ctx context.Context, in *PageReq, out *PageResp) error
|
||||
}
|
||||
type Page struct {
|
||||
page
|
||||
}
|
||||
h := &pageHandler{hdlr}
|
||||
return s.Handle(s.NewHandler(&Page{h}, opts...))
|
||||
}
|
||||
|
||||
type pageHandler struct {
|
||||
PageHandler
|
||||
}
|
||||
|
||||
func (h *pageHandler) Page(ctx context.Context, in *PageReq, out *PageResp) error {
|
||||
return h.PageHandler.Page(ctx, in, out)
|
||||
}
|
||||
|
||||
// Api Endpoints for ShowProductDetail service
|
||||
|
||||
func NewShowProductDetailEndpoints() []*api.Endpoint {
|
||||
return []*api.Endpoint{}
|
||||
}
|
||||
|
||||
// Client API for ShowProductDetail service
|
||||
|
||||
type ShowProductDetailService interface {
|
||||
// rpc 服务
|
||||
ShowProductDetail(ctx context.Context, in *ProductDetailReq, opts ...client.CallOption) (*ProductDetailResp, error)
|
||||
}
|
||||
|
||||
type showProductDetailService struct {
|
||||
c client.Client
|
||||
name string
|
||||
}
|
||||
|
||||
func NewShowProductDetailService(name string, c client.Client) ShowProductDetailService {
|
||||
return &showProductDetailService{
|
||||
c: c,
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *showProductDetailService) ShowProductDetail(ctx context.Context, in *ProductDetailReq, opts ...client.CallOption) (*ProductDetailResp, error) {
|
||||
req := c.c.NewRequest(c.name, "ShowProductDetail.ShowProductDetail", in)
|
||||
out := new(ProductDetailResp)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Server API for ShowProductDetail service
|
||||
|
||||
type ShowProductDetailHandler interface {
|
||||
// rpc 服务
|
||||
ShowProductDetail(context.Context, *ProductDetailReq, *ProductDetailResp) error
|
||||
}
|
||||
|
||||
func RegisterShowProductDetailHandler(s server.Server, hdlr ShowProductDetailHandler, opts ...server.HandlerOption) error {
|
||||
type showProductDetail interface {
|
||||
ShowProductDetail(ctx context.Context, in *ProductDetailReq, out *ProductDetailResp) error
|
||||
}
|
||||
type ShowProductDetail struct {
|
||||
showProductDetail
|
||||
}
|
||||
h := &showProductDetailHandler{hdlr}
|
||||
return s.Handle(s.NewHandler(&ShowProductDetail{h}, opts...))
|
||||
}
|
||||
|
||||
type showProductDetailHandler struct {
|
||||
ShowProductDetailHandler
|
||||
}
|
||||
|
||||
func (h *showProductDetailHandler) ShowProductDetail(ctx context.Context, in *ProductDetailReq, out *ProductDetailResp) error {
|
||||
return h.ShowProductDetailHandler.ShowProductDetail(ctx, in, out)
|
||||
}
|
||||
|
||||
// Api Endpoints for ShowProductSku service
|
||||
|
||||
func NewShowProductSkuEndpoints() []*api.Endpoint {
|
||||
return []*api.Endpoint{}
|
||||
}
|
||||
|
||||
// Client API for ShowProductSku service
|
||||
|
||||
type ShowProductSkuService interface {
|
||||
// rpc 服务
|
||||
ShowProductSku(ctx context.Context, in *ProductSkuReq, opts ...client.CallOption) (*ProductSkuResp, error)
|
||||
}
|
||||
|
||||
type showProductSkuService struct {
|
||||
c client.Client
|
||||
name string
|
||||
}
|
||||
|
||||
func NewShowProductSkuService(name string, c client.Client) ShowProductSkuService {
|
||||
return &showProductSkuService{
|
||||
c: c,
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *showProductSkuService) ShowProductSku(ctx context.Context, in *ProductSkuReq, opts ...client.CallOption) (*ProductSkuResp, error) {
|
||||
req := c.c.NewRequest(c.name, "ShowProductSku.ShowProductSku", in)
|
||||
out := new(ProductSkuResp)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Server API for ShowProductSku service
|
||||
|
||||
type ShowProductSkuHandler interface {
|
||||
// rpc 服务
|
||||
ShowProductSku(context.Context, *ProductSkuReq, *ProductSkuResp) error
|
||||
}
|
||||
|
||||
func RegisterShowProductSkuHandler(s server.Server, hdlr ShowProductSkuHandler, opts ...server.HandlerOption) error {
|
||||
type showProductSku interface {
|
||||
ShowProductSku(ctx context.Context, in *ProductSkuReq, out *ProductSkuResp) error
|
||||
}
|
||||
type ShowProductSku struct {
|
||||
showProductSku
|
||||
}
|
||||
h := &showProductSkuHandler{hdlr}
|
||||
return s.Handle(s.NewHandler(&ShowProductSku{h}, opts...))
|
||||
}
|
||||
|
||||
type showProductSkuHandler struct {
|
||||
ShowProductSkuHandler
|
||||
}
|
||||
|
||||
func (h *showProductSkuHandler) ShowProductSku(ctx context.Context, in *ProductSkuReq, out *ProductSkuResp) error {
|
||||
return h.ShowProductSkuHandler.ShowProductSku(ctx, in, out)
|
||||
}
|
||||
|
||||
// Api Endpoints for ShowDetailSku service
|
||||
|
||||
func NewShowDetailSkuEndpoints() []*api.Endpoint {
|
||||
return []*api.Endpoint{}
|
||||
}
|
||||
|
||||
// Client API for ShowDetailSku service
|
||||
|
||||
type ShowDetailSkuService interface {
|
||||
// rpc 服务
|
||||
ShowDetailSku(ctx context.Context, in *ProductDetailReq, opts ...client.CallOption) (*ProductSkuResp, error)
|
||||
}
|
||||
|
||||
type showDetailSkuService struct {
|
||||
c client.Client
|
||||
name string
|
||||
}
|
||||
|
||||
func NewShowDetailSkuService(name string, c client.Client) ShowDetailSkuService {
|
||||
return &showDetailSkuService{
|
||||
c: c,
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *showDetailSkuService) ShowDetailSku(ctx context.Context, in *ProductDetailReq, opts ...client.CallOption) (*ProductSkuResp, error) {
|
||||
req := c.c.NewRequest(c.name, "ShowDetailSku.ShowDetailSku", in)
|
||||
out := new(ProductSkuResp)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Server API for ShowDetailSku service
|
||||
|
||||
type ShowDetailSkuHandler interface {
|
||||
// rpc 服务
|
||||
ShowDetailSku(context.Context, *ProductDetailReq, *ProductSkuResp) error
|
||||
}
|
||||
|
||||
func RegisterShowDetailSkuHandler(s server.Server, hdlr ShowDetailSkuHandler, opts ...server.HandlerOption) error {
|
||||
type showDetailSku interface {
|
||||
ShowDetailSku(ctx context.Context, in *ProductDetailReq, out *ProductSkuResp) error
|
||||
}
|
||||
type ShowDetailSku struct {
|
||||
showDetailSku
|
||||
}
|
||||
h := &showDetailSkuHandler{hdlr}
|
||||
return s.Handle(s.NewHandler(&ShowDetailSku{h}, opts...))
|
||||
}
|
||||
|
||||
type showDetailSkuHandler struct {
|
||||
ShowDetailSkuHandler
|
||||
}
|
||||
|
||||
func (h *showDetailSkuHandler) ShowDetailSku(ctx context.Context, in *ProductDetailReq, out *ProductSkuResp) error {
|
||||
return h.ShowDetailSkuHandler.ShowDetailSku(ctx, in, out)
|
||||
}
|
||||
|
||||
// Api Endpoints for GetUserToken service
|
||||
|
||||
func NewGetUserTokenEndpoints() []*api.Endpoint {
|
||||
return []*api.Endpoint{}
|
||||
}
|
||||
|
||||
// Client API for GetUserToken service
|
||||
|
||||
type GetUserTokenService interface {
|
||||
// rpc 服务
|
||||
GetUserToken(ctx context.Context, in *TokenReq, opts ...client.CallOption) (*TokenResp, error)
|
||||
}
|
||||
|
||||
type getUserTokenService struct {
|
||||
c client.Client
|
||||
name string
|
||||
}
|
||||
|
||||
func NewGetUserTokenService(name string, c client.Client) GetUserTokenService {
|
||||
return &getUserTokenService{
|
||||
c: c,
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *getUserTokenService) GetUserToken(ctx context.Context, in *TokenReq, opts ...client.CallOption) (*TokenResp, error) {
|
||||
req := c.c.NewRequest(c.name, "GetUserToken.GetUserToken", in)
|
||||
out := new(TokenResp)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Server API for GetUserToken service
|
||||
|
||||
type GetUserTokenHandler interface {
|
||||
// rpc 服务
|
||||
GetUserToken(context.Context, *TokenReq, *TokenResp) error
|
||||
}
|
||||
|
||||
func RegisterGetUserTokenHandler(s server.Server, hdlr GetUserTokenHandler, opts ...server.HandlerOption) error {
|
||||
type getUserToken interface {
|
||||
GetUserToken(ctx context.Context, in *TokenReq, out *TokenResp) error
|
||||
}
|
||||
type GetUserToken struct {
|
||||
getUserToken
|
||||
}
|
||||
h := &getUserTokenHandler{hdlr}
|
||||
return s.Handle(s.NewHandler(&GetUserToken{h}, opts...))
|
||||
}
|
||||
|
||||
type getUserTokenHandler struct {
|
||||
GetUserTokenHandler
|
||||
}
|
||||
|
||||
func (h *getUserTokenHandler) GetUserToken(ctx context.Context, in *TokenReq, out *TokenResp) error {
|
||||
return h.GetUserTokenHandler.GetUserToken(ctx, in, out)
|
||||
}
|
||||
|
||||
// Api Endpoints for UpdateSku service
|
||||
|
||||
func NewUpdateSkuEndpoints() []*api.Endpoint {
|
||||
return []*api.Endpoint{}
|
||||
}
|
||||
|
||||
// Client API for UpdateSku service
|
||||
|
||||
type UpdateSkuService interface {
|
||||
UpdateSku(ctx context.Context, in *UpdateSkuReq, opts ...client.CallOption) (*UpdateSkuResp, error)
|
||||
}
|
||||
|
||||
type updateSkuService struct {
|
||||
c client.Client
|
||||
name string
|
||||
}
|
||||
|
||||
func NewUpdateSkuService(name string, c client.Client) UpdateSkuService {
|
||||
return &updateSkuService{
|
||||
c: c,
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *updateSkuService) UpdateSku(ctx context.Context, in *UpdateSkuReq, opts ...client.CallOption) (*UpdateSkuResp, error) {
|
||||
req := c.c.NewRequest(c.name, "UpdateSku.UpdateSku", in)
|
||||
out := new(UpdateSkuResp)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Server API for UpdateSku service
|
||||
|
||||
type UpdateSkuHandler interface {
|
||||
UpdateSku(context.Context, *UpdateSkuReq, *UpdateSkuResp) error
|
||||
}
|
||||
|
||||
func RegisterUpdateSkuHandler(s server.Server, hdlr UpdateSkuHandler, opts ...server.HandlerOption) error {
|
||||
type updateSku interface {
|
||||
UpdateSku(ctx context.Context, in *UpdateSkuReq, out *UpdateSkuResp) error
|
||||
}
|
||||
type UpdateSku struct {
|
||||
updateSku
|
||||
}
|
||||
h := &updateSkuHandler{hdlr}
|
||||
return s.Handle(s.NewHandler(&UpdateSku{h}, opts...))
|
||||
}
|
||||
|
||||
type updateSkuHandler struct {
|
||||
UpdateSkuHandler
|
||||
}
|
||||
|
||||
func (h *updateSkuHandler) UpdateSku(ctx context.Context, in *UpdateSkuReq, out *UpdateSkuResp) error {
|
||||
return h.UpdateSkuHandler.UpdateSku(ctx, in, out)
|
||||
}
|
Loading…
Reference in new issue