From 4117638ad44036fa9fb90359882bc5850955a304 Mon Sep 17 00:00:00 2001 From: shenzhuan Date: Mon, 24 Oct 2022 15:37:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E5=B8=83=E5=BC=8F=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shoppingCart-service/client/client.go | 27 +- shoppingCart-service/proto/cart.pb.go | 216 +++++++++-- shoppingCart-service/proto/cart.pb.micro.go | 61 +++ shoppingCart-service/proto/cart.proto | 15 + user-service/common/config.go | 4 +- user-service/common/utils.go | 11 + .../domain/repository/user_repository.go | 11 +- user-service/handler/user.go | 21 +- user-service/main.go | 2 +- user-service/proto/user.pb.go | 354 ++++++++++++++++-- user-service/proto/user.pb.micro.go | 65 +++- user-service/proto/user.proto | 14 + 12 files changed, 716 insertions(+), 85 deletions(-) diff --git a/shoppingCart-service/client/client.go b/shoppingCart-service/client/client.go index 1b71f53..54dbe59 100644 --- a/shoppingCart-service/client/client.go +++ b/shoppingCart-service/client/client.go @@ -58,8 +58,9 @@ func main() { micro.WrapClient(roundrobin.NewClientWrapper()), ) client := proto.NewAddCartService("shop-cart", rpcServer.Client()) - clientA := proto.NewShowProductDetailService("shop-product", rpcServer.Client()) - clientB := proto.NewShowDetailSkuService("shop-product", rpcServer.Client()) + ShowProductDetailClient := proto.NewShowProductDetailService("shop-product", rpcServer.Client()) + ShowDetailSkuClient := proto.NewShowDetailSkuService("shop-product", rpcServer.Client()) + GetUserTokenClient := proto.NewGetUserTokenService("shop-user", rpcServer.Client()) //分页查询商品列表 router.GET("/increase", func(c *gin.Context) { // "number": 0, @@ -75,11 +76,28 @@ func main() { ProductId: int32(productId), ProductSkuId: int32(productSkuId), } + resp, err := client.AddCart(context.TODO(), req) + //Token校验 + //拼接请求信息 + tokenReq := &proto.TokenReq{ + Uuid: c.Request.Header["Uuid"][0], + } + + //响应 + tokenResp, err := GetUserTokenClient.GetUserToken(context.TODO(), tokenReq) + + if err != nil || tokenResp.IsLogin == false { + log.Println("GetUserToken err : ", err) + common.RespFail(c.Writer, resp, "未登录!") + return + } + log.Println("GetUserToken success : ", tokenResp) + //商品详情 reqDetail := &proto.ProductDetailReq{ Id: int32(productId), } - respDetail, err := clientA.ShowProductDetail(context.TODO(), reqDetail) + respDetail, err := ShowProductDetailClient.ShowProductDetail(context.TODO(), reqDetail) if respDetail != nil { req.ProductName = respDetail.ProductDetail[0].Name req.ProductMainPicture = respDetail.ProductDetail[0].MainPicture @@ -88,7 +106,7 @@ func main() { log.Println(" /ShowProductDetail resp :", respDetail) //SKU详情 reqDetail.Id = req.ProductSkuId - respSkuDetail, err := clientB.ShowDetailSku(context.TODO(), reqDetail) + respSkuDetail, err := ShowDetailSkuClient.ShowDetailSku(context.TODO(), reqDetail) log.Println(" /ShowDetailSku resp :", respSkuDetail) @@ -100,7 +118,6 @@ func main() { return } - resp, err := client.AddCart(context.TODO(), req) resp.ProductSkuSimple = respSkuDetail.ProductSku[0] resp.ProductSimple = respDetail.ProductDetail[0] diff --git a/shoppingCart-service/proto/cart.pb.go b/shoppingCart-service/proto/cart.pb.go index 63833f5..240b4e6 100644 --- a/shoppingCart-service/proto/cart.pb.go +++ b/shoppingCart-service/proto/cart.pb.go @@ -1028,6 +1028,110 @@ func (x *ProductSkuResp) GetProductSku() []*ProductSku { return nil } +// 获取 分布式 token +type TokenReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Uuid string `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"` +} + +func (x *TokenReq) Reset() { + *x = TokenReq{} + if protoimpl.UnsafeEnabled { + mi := &file_cart_proto_msgTypes[12] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TokenReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TokenReq) ProtoMessage() {} + +func (x *TokenReq) ProtoReflect() protoreflect.Message { + mi := &file_cart_proto_msgTypes[12] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TokenReq.ProtoReflect.Descriptor instead. +func (*TokenReq) Descriptor() ([]byte, []int) { + return file_cart_proto_rawDescGZIP(), []int{12} +} + +func (x *TokenReq) GetUuid() string { + if x != nil { + return x.Uuid + } + return "" +} + +// 响应 resp struct +type TokenResp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` + IsLogin bool `protobuf:"varint,2,opt,name=isLogin,proto3" json:"isLogin,omitempty"` +} + +func (x *TokenResp) Reset() { + *x = TokenResp{} + if protoimpl.UnsafeEnabled { + mi := &file_cart_proto_msgTypes[13] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TokenResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TokenResp) ProtoMessage() {} + +func (x *TokenResp) ProtoReflect() protoreflect.Message { + mi := &file_cart_proto_msgTypes[13] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TokenResp.ProtoReflect.Descriptor instead. +func (*TokenResp) Descriptor() ([]byte, []int) { + return file_cart_proto_rawDescGZIP(), []int{13} +} + +func (x *TokenResp) GetToken() string { + if x != nil { + return x.Token + } + return "" +} + +func (x *TokenResp) GetIsLogin() bool { + if x != nil { + return x.IsLogin + } + return false +} + var File_cart_proto protoreflect.FileDescriptor var file_cart_proto_rawDesc = []byte{ @@ -1171,32 +1275,42 @@ var file_cart_proto_rawDesc = []byte{ 0x75, 0x52, 0x65, 0x73, 0x70, 0x12, 0x31, 0x0a, 0x0a, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x53, 0x6b, 0x75, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x53, 0x6b, 0x75, 0x52, 0x0a, 0x70, 0x72, - 0x6f, 0x64, 0x75, 0x63, 0x74, 0x53, 0x6b, 0x75, 0x32, 0x3d, 0x0a, 0x07, 0x41, 0x64, 0x64, 0x43, - 0x61, 0x72, 0x74, 0x12, 0x32, 0x0a, 0x07, 0x41, 0x64, 0x64, 0x43, 0x61, 0x72, 0x74, 0x12, 0x11, + 0x6f, 0x64, 0x75, 0x63, 0x74, 0x53, 0x6b, 0x75, 0x22, 0x1e, 0x0a, 0x08, 0x54, 0x6f, 0x6b, 0x65, + 0x6e, 0x52, 0x65, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x04, 0x75, 0x75, 0x69, 0x64, 0x22, 0x3b, 0x0a, 0x09, 0x54, 0x6f, 0x6b, 0x65, + 0x6e, 0x52, 0x65, 0x73, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x69, + 0x73, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x69, 0x73, + 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x32, 0x3d, 0x0a, 0x07, 0x41, 0x64, 0x64, 0x43, 0x61, 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, - 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, 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, - 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2f, 0x3b, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 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, 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, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2f, 0x3b, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -1211,7 +1325,7 @@ func file_cart_proto_rawDescGZIP() []byte { return file_cart_proto_rawDescData } -var file_cart_proto_msgTypes = make([]protoimpl.MessageInfo, 13) +var file_cart_proto_msgTypes = make([]protoimpl.MessageInfo, 15) var file_cart_proto_goTypes = []interface{}{ (*ShoppingCart)(nil), // 0: proto.ShoppingCart (*AddCartReq)(nil), // 1: proto.AddCartReq @@ -1225,12 +1339,14 @@ var file_cart_proto_goTypes = []interface{}{ (*ProductSku)(nil), // 9: proto.ProductSku (*ProductSkuReq)(nil), // 10: proto.ProductSkuReq (*ProductSkuResp)(nil), // 11: proto.ProductSkuResp - nil, // 12: proto.Product.LabelListEntry + (*TokenReq)(nil), // 12: proto.TokenReq + (*TokenResp)(nil), // 13: proto.TokenResp + nil, // 14: proto.Product.LabelListEntry } var file_cart_proto_depIdxs = []int32{ 6, // 0: proto.AddCartResp.productSimple:type_name -> proto.ProductDetail 9, // 1: proto.AddCartResp.productSkuSimple:type_name -> proto.ProductSku - 12, // 2: proto.Product.labelList:type_name -> proto.Product.LabelListEntry + 14, // 2: proto.Product.labelList:type_name -> proto.Product.LabelListEntry 3, // 3: proto.PageResp.product:type_name -> proto.Product 6, // 4: proto.ProductDetailResp.productDetail:type_name -> proto.ProductDetail 9, // 5: proto.ProductSkuResp.productSku:type_name -> proto.ProductSku @@ -1239,13 +1355,15 @@ var file_cart_proto_depIdxs = []int32{ 7, // 8: proto.ShowProductDetail.ShowProductDetail:input_type -> proto.ProductDetailReq 10, // 9: proto.ShowProductSku.ShowProductSku:input_type -> proto.ProductSkuReq 7, // 10: proto.ShowDetailSku.ShowDetailSku:input_type -> proto.ProductDetailReq - 2, // 11: proto.AddCart.AddCart:output_type -> proto.AddCartResp - 5, // 12: proto.Page.Page:output_type -> proto.PageResp - 8, // 13: proto.ShowProductDetail.ShowProductDetail:output_type -> proto.ProductDetailResp - 11, // 14: proto.ShowProductSku.ShowProductSku:output_type -> proto.ProductSkuResp - 11, // 15: proto.ShowDetailSku.ShowDetailSku:output_type -> proto.ProductSkuResp - 11, // [11:16] is the sub-list for method output_type - 6, // [6:11] is the sub-list for method input_type + 12, // 11: proto.GetUserToken.GetUserToken:input_type -> proto.TokenReq + 2, // 12: proto.AddCart.AddCart:output_type -> proto.AddCartResp + 5, // 13: proto.Page.Page:output_type -> proto.PageResp + 8, // 14: proto.ShowProductDetail.ShowProductDetail:output_type -> proto.ProductDetailResp + 11, // 15: proto.ShowProductSku.ShowProductSku:output_type -> proto.ProductSkuResp + 11, // 16: proto.ShowDetailSku.ShowDetailSku:output_type -> proto.ProductSkuResp + 13, // 17: proto.GetUserToken.GetUserToken:output_type -> proto.TokenResp + 12, // [12:18] is the sub-list for method output_type + 6, // [6:12] is the sub-list for method input_type 6, // [6:6] is the sub-list for extension type_name 6, // [6:6] is the sub-list for extension extendee 0, // [0:6] is the sub-list for field type_name @@ -1401,6 +1519,30 @@ func file_cart_proto_init() { return nil } } + file_cart_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TokenReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_cart_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TokenResp); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -1408,9 +1550,9 @@ func file_cart_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_cart_proto_rawDesc, NumEnums: 0, - NumMessages: 13, + NumMessages: 15, NumExtensions: 0, - NumServices: 5, + NumServices: 6, }, GoTypes: file_cart_proto_goTypes, DependencyIndexes: file_cart_proto_depIdxs, diff --git a/shoppingCart-service/proto/cart.pb.micro.go b/shoppingCart-service/proto/cart.pb.micro.go index 6024a90..eda1a72 100644 --- a/shoppingCart-service/proto/cart.pb.micro.go +++ b/shoppingCart-service/proto/cart.pb.micro.go @@ -331,3 +331,64 @@ type showDetailSkuHandler struct { 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) +} diff --git a/shoppingCart-service/proto/cart.proto b/shoppingCart-service/proto/cart.proto index bedbbc2..90110be 100644 --- a/shoppingCart-service/proto/cart.proto +++ b/shoppingCart-service/proto/cart.proto @@ -214,3 +214,18 @@ service ShowDetailSku { //rpc 服务 rpc ShowDetailSku (ProductDetailReq) returns (ProductSkuResp){} } + +// 获取 分布式 token +message TokenReq { + string uuid = 1; +} +//响应 resp struct +message TokenResp{ + string token = 1; + bool isLogin=2; +} +//RPC 服务 接口 +service GetUserToken { + //rpc 服务 + rpc GetUserToken (TokenReq) returns (TokenResp){} +} \ No newline at end of file diff --git a/user-service/common/config.go b/user-service/common/config.go index dd7b636..e4246e7 100644 --- a/user-service/common/config.go +++ b/user-service/common/config.go @@ -22,8 +22,8 @@ func GetConsulConfig(url string, fileKey string) (*viper.Viper, error) { err := conf.ReadRemoteConfig() if err != nil { log.Println("viper conf err :", err) - } else { - log.Println("viper conf :", conf) + //}else { + //log.Println("viper conf :", conf) } return conf, nil } diff --git a/user-service/common/utils.go b/user-service/common/utils.go index 5568ebe..d5a923f 100644 --- a/user-service/common/utils.go +++ b/user-service/common/utils.go @@ -2,6 +2,7 @@ package common import ( "math" + "strconv" ) /* @@ -52,3 +53,13 @@ func ToInt(intput string) int { } return sum } + +// int 转 二进制的字符串 +func ConverToBinary(n int) string { + res := "" + for ; n > 0; n /= 2 { + lsb := n % 2 + res = strconv.Itoa(lsb) + res + } + return res +} diff --git a/user-service/domain/repository/user_repository.go b/user-service/domain/repository/user_repository.go index 79dc8e6..764cb6e 100644 --- a/user-service/domain/repository/user_repository.go +++ b/user-service/domain/repository/user_repository.go @@ -2,12 +2,12 @@ package repository import ( "errors" + "fmt" "github.com/go-redis/redis/v8" + "gorm.io/gorm" "gouser/common" "gouser/domain/model" "time" - - "gorm.io/gorm" ) /** @@ -52,7 +52,12 @@ func (u *UserRepository) Login(clientId int32, phone string, systemId int32, ver } } func (u *UserRepository) SetUserToken(key string, val []byte, timeTTL time.Duration) { - common.SetUserToken(u.red, key, val, timeTTL) + + intKey := common.ToInt(key) + binKey := common.ConverToBinary(intKey) + fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>", binKey) + + common.SetUserToken(u.red, binKey, val, timeTTL) } func (u *UserRepository) GetUserToken(key string) string { diff --git a/user-service/handler/user.go b/user-service/handler/user.go index 3029bfa..eb76739 100644 --- a/user-service/handler/user.go +++ b/user-service/handler/user.go @@ -49,12 +49,15 @@ func UserForResp(userModel *model.User, resp *proto.LoginResp) *proto.LoginResp return resp } -//func (u *User) GetUserToken(ctx context.Context, loginRequest *proto.LoginRequest, loginResp *proto.LoginResp) bool { -// userInfo, err := u.UserDataService.GetUserToken() -// if err != nil { -// return err -// } -// fmt.Println(">>>>>>>>>>>>> login success :", userInfo) -// UserForResp(userInfo, loginResp) -// return nil -//} +func (u *User) GetUserToken(ctx context.Context, req *proto.TokenReq, resp *proto.TokenResp) error { + res := u.UserDataService.GetUserToken(req.GetUuid()) + if res != "" { + resp.IsLogin = true + resp.Token = res + fmt.Println(">>>>>>>>>>>>> GetUserToken success :", res) + } else { + resp.IsLogin = false + resp.Token = "" + } + return nil +} diff --git a/user-service/main.go b/user-service/main.go index c81d5d4..df8e3c0 100644 --- a/user-service/main.go +++ b/user-service/main.go @@ -54,7 +54,7 @@ func main() { userDataService := service.NewUserDataService(repository.NewUserRepository(db, red)) //4.注册handler proto.RegisterLoginHandler(repcService.Server(), &handler.User{userDataService}) - + proto.RegisterGetUserTokenHandler(repcService.Server(), &handler.User{userDataService}) //5.启动服务 if err := repcService.Run(); err != nil { log.Println("start user service err :", err) diff --git a/user-service/proto/user.pb.go b/user-service/proto/user.pb.go index 725520c..7fc00f0 100644 --- a/user-service/proto/user.pb.go +++ b/user-service/proto/user.pb.go @@ -11,6 +11,10 @@ package proto import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" @@ -24,18 +28,18 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -//* -//"avatar": "", -//"clientId": 0, -//"employeeId": 0, -//"id": 0, -//"nickname": "", -//"phone": "", -//"sessionId": "", -//"systemId": 0, -//"token": "", -//"tokenExpireTime": "", -//"unionId": "" +// * +// "avatar": "", +// "clientId": 0, +// "employeeId": 0, +// "id": 0, +// "nickname": "", +// "phone": "", +// "sessionId": "", +// "systemId": 0, +// "token": "", +// "tokenExpireTime": "", +// "unionId": "" type User struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -155,7 +159,7 @@ func (x *User) GetId() int32 { return 0 } -//请求 request struct +// 请求 request struct type LoginRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -227,7 +231,7 @@ func (x *LoginRequest) GetVerificationCode() string { return "" } -//响应 resp struct +// 响应 resp struct type LoginResp struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -283,6 +287,110 @@ func (x *LoginResp) GetUser() *User { return nil } +// 获取 分布式 token +type TokenReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Uuid string `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"` +} + +func (x *TokenReq) Reset() { + *x = TokenReq{} + if protoimpl.UnsafeEnabled { + mi := &file_user_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TokenReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TokenReq) ProtoMessage() {} + +func (x *TokenReq) ProtoReflect() protoreflect.Message { + mi := &file_user_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TokenReq.ProtoReflect.Descriptor instead. +func (*TokenReq) Descriptor() ([]byte, []int) { + return file_user_proto_rawDescGZIP(), []int{3} +} + +func (x *TokenReq) GetUuid() string { + if x != nil { + return x.Uuid + } + return "" +} + +// 响应 resp struct +type TokenResp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` + IsLogin bool `protobuf:"varint,2,opt,name=isLogin,proto3" json:"isLogin,omitempty"` +} + +func (x *TokenResp) Reset() { + *x = TokenResp{} + if protoimpl.UnsafeEnabled { + mi := &file_user_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TokenResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TokenResp) ProtoMessage() {} + +func (x *TokenResp) ProtoReflect() protoreflect.Message { + mi := &file_user_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TokenResp.ProtoReflect.Descriptor instead. +func (*TokenResp) Descriptor() ([]byte, []int) { + return file_user_proto_rawDescGZIP(), []int{4} +} + +func (x *TokenResp) GetToken() string { + if x != nil { + return x.Token + } + return "" +} + +func (x *TokenResp) GetIsLogin() bool { + if x != nil { + return x.IsLogin + } + return false +} + var File_user_proto protoreflect.FileDescriptor var file_user_proto_rawDesc = []byte{ @@ -317,12 +425,22 @@ var file_user_proto_rawDesc = []byte{ 0x73, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x1f, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x55, - 0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x32, 0x39, 0x0a, 0x05, 0x4c, 0x6f, 0x67, - 0x69, 0x6e, 0x12, 0x30, 0x0a, 0x05, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x12, 0x13, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x10, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 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, + 0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x22, 0x1e, 0x0a, 0x08, 0x54, 0x6f, 0x6b, + 0x65, 0x6e, 0x52, 0x65, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x04, 0x75, 0x75, 0x69, 0x64, 0x22, 0x3b, 0x0a, 0x09, 0x54, 0x6f, 0x6b, + 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x18, 0x0a, 0x07, + 0x69, 0x73, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x69, + 0x73, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x32, 0x39, 0x0a, 0x05, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x12, + 0x30, 0x0a, 0x05, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x12, 0x13, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 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, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2f, 0x3b, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -337,18 +455,22 @@ func file_user_proto_rawDescGZIP() []byte { return file_user_proto_rawDescData } -var file_user_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_user_proto_msgTypes = make([]protoimpl.MessageInfo, 5) var file_user_proto_goTypes = []interface{}{ (*User)(nil), // 0: proto.User (*LoginRequest)(nil), // 1: proto.LoginRequest (*LoginResp)(nil), // 2: proto.LoginResp + (*TokenReq)(nil), // 3: proto.TokenReq + (*TokenResp)(nil), // 4: proto.TokenResp } var file_user_proto_depIdxs = []int32{ 0, // 0: proto.LoginResp.user:type_name -> proto.User 1, // 1: proto.Login.Login:input_type -> proto.LoginRequest - 2, // 2: proto.Login.Login:output_type -> proto.LoginResp - 2, // [2:3] is the sub-list for method output_type - 1, // [1:2] is the sub-list for method input_type + 3, // 2: proto.GetUserToken.GetUserToken:input_type -> proto.TokenReq + 2, // 3: proto.Login.Login:output_type -> proto.LoginResp + 4, // 4: proto.GetUserToken.GetUserToken:output_type -> proto.TokenResp + 3, // [3:5] is the sub-list for method output_type + 1, // [1:3] is the sub-list for method input_type 1, // [1:1] is the sub-list for extension type_name 1, // [1:1] is the sub-list for extension extendee 0, // [0:1] is the sub-list for field type_name @@ -396,6 +518,30 @@ func file_user_proto_init() { return nil } } + file_user_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TokenReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_user_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TokenResp); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -403,9 +549,9 @@ func file_user_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_user_proto_rawDesc, NumEnums: 0, - NumMessages: 3, + NumMessages: 5, NumExtensions: 0, - NumServices: 1, + NumServices: 2, }, GoTypes: file_user_proto_goTypes, DependencyIndexes: file_user_proto_depIdxs, @@ -416,3 +562,159 @@ func file_user_proto_init() { file_user_proto_goTypes = nil file_user_proto_depIdxs = nil } + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConnInterface + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion6 + +// LoginClient is the client API for Login service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type LoginClient interface { + // rpc 服务 + Login(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResp, error) +} + +type loginClient struct { + cc grpc.ClientConnInterface +} + +func NewLoginClient(cc grpc.ClientConnInterface) LoginClient { + return &loginClient{cc} +} + +func (c *loginClient) Login(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResp, error) { + out := new(LoginResp) + err := c.cc.Invoke(ctx, "/proto.Login/Login", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// LoginServer is the server API for Login service. +type LoginServer interface { + // rpc 服务 + Login(context.Context, *LoginRequest) (*LoginResp, error) +} + +// UnimplementedLoginServer can be embedded to have forward compatible implementations. +type UnimplementedLoginServer struct { +} + +func (*UnimplementedLoginServer) Login(context.Context, *LoginRequest) (*LoginResp, error) { + return nil, status.Errorf(codes.Unimplemented, "method Login not implemented") +} + +func RegisterLoginServer(s *grpc.Server, srv LoginServer) { + s.RegisterService(&_Login_serviceDesc, srv) +} + +func _Login_Login_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(LoginRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(LoginServer).Login(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Login/Login", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(LoginServer).Login(ctx, req.(*LoginRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Login_serviceDesc = grpc.ServiceDesc{ + ServiceName: "proto.Login", + HandlerType: (*LoginServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Login", + Handler: _Login_Login_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "user.proto", +} + +// GetUserTokenClient is the client API for GetUserToken service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type GetUserTokenClient interface { + // rpc 服务 + GetUserToken(ctx context.Context, in *TokenReq, opts ...grpc.CallOption) (*TokenResp, error) +} + +type getUserTokenClient struct { + cc grpc.ClientConnInterface +} + +func NewGetUserTokenClient(cc grpc.ClientConnInterface) GetUserTokenClient { + return &getUserTokenClient{cc} +} + +func (c *getUserTokenClient) GetUserToken(ctx context.Context, in *TokenReq, opts ...grpc.CallOption) (*TokenResp, error) { + out := new(TokenResp) + err := c.cc.Invoke(ctx, "/proto.GetUserToken/GetUserToken", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// GetUserTokenServer is the server API for GetUserToken service. +type GetUserTokenServer interface { + // rpc 服务 + GetUserToken(context.Context, *TokenReq) (*TokenResp, error) +} + +// UnimplementedGetUserTokenServer can be embedded to have forward compatible implementations. +type UnimplementedGetUserTokenServer struct { +} + +func (*UnimplementedGetUserTokenServer) GetUserToken(context.Context, *TokenReq) (*TokenResp, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetUserToken not implemented") +} + +func RegisterGetUserTokenServer(s *grpc.Server, srv GetUserTokenServer) { + s.RegisterService(&_GetUserToken_serviceDesc, srv) +} + +func _GetUserToken_GetUserToken_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(TokenReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(GetUserTokenServer).GetUserToken(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.GetUserToken/GetUserToken", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(GetUserTokenServer).GetUserToken(ctx, req.(*TokenReq)) + } + return interceptor(ctx, in, info, handler) +} + +var _GetUserToken_serviceDesc = grpc.ServiceDesc{ + ServiceName: "proto.GetUserToken", + HandlerType: (*GetUserTokenServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetUserToken", + Handler: _GetUserToken_GetUserToken_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "user.proto", +} diff --git a/user-service/proto/user.pb.micro.go b/user-service/proto/user.pb.micro.go index e6c5fa3..9e0cf4e 100644 --- a/user-service/proto/user.pb.micro.go +++ b/user-service/proto/user.pb.micro.go @@ -36,7 +36,7 @@ func NewLoginEndpoints() []*api.Endpoint { // Client API for Login service type LoginService interface { - //rpc 服务 + // rpc 服务 Login(ctx context.Context, in *LoginRequest, opts ...client.CallOption) (*LoginResp, error) } @@ -65,7 +65,7 @@ func (c *loginService) Login(ctx context.Context, in *LoginRequest, opts ...clie // Server API for Login service type LoginHandler interface { - //rpc 服务 + // rpc 服务 Login(context.Context, *LoginRequest, *LoginResp) error } @@ -87,3 +87,64 @@ type loginHandler struct { func (h *loginHandler) Login(ctx context.Context, in *LoginRequest, out *LoginResp) error { return h.LoginHandler.Login(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) +} diff --git a/user-service/proto/user.proto b/user-service/proto/user.proto index a9cbd84..cf6b9d6 100644 --- a/user-service/proto/user.proto +++ b/user-service/proto/user.proto @@ -57,3 +57,17 @@ service Login { rpc Login (LoginRequest) returns (LoginResp){} } +// 获取 分布式 token +message TokenReq { + string uuid = 1; +} +//响应 resp struct +message TokenResp{ + string token = 1; + bool isLogin=2; +} +//RPC 服务 接口 +service GetUserToken { + //rpc 服务 + rpc GetUserToken (TokenReq) returns (TokenResp){} +} \ No newline at end of file