add: grpc server

This commit is contained in:
viletyy 2021-06-17 00:45:37 +08:00
parent cd72a28bb7
commit e5f19ac950
12 changed files with 741 additions and 12 deletions

3
go.mod
View File

@ -20,6 +20,7 @@ require (
github.com/onsi/ginkgo v1.16.4 // indirect
github.com/onsi/gomega v1.13.0 // indirect
github.com/opentracing/opentracing-go v1.2.0
github.com/smacker/opentracing-gorm v0.0.0-20181207094635-cd4974441042 // indirect
github.com/spf13/viper v1.7.1
github.com/swaggo/gin-swagger v1.3.0
github.com/swaggo/swag v1.7.0
@ -28,6 +29,8 @@ require (
github.com/viletyy/yolk v1.0.1
go.uber.org/atomic v1.8.0 // indirect
go.uber.org/zap v1.17.0
google.golang.org/grpc v1.38.0
google.golang.org/protobuf v1.26.0
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
)

35
initialize/grpc.go Normal file
View File

@ -0,0 +1,35 @@
/*
* @Date: 2021-06-17 00:19:32
* @LastEditors: viletyy
* @LastEditTime: 2021-06-17 00:33:38
* @FilePath: /potato/initialize/grpc.go
*/
package initialize
import (
"net"
"github.com/viletyy/potato/global"
pb "github.com/viletyy/potato/proto/basic"
"github.com/viletyy/potato/server/basic"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
func RunGrpc() {
server := grpc.NewServer()
pb.RegisterVendorServiceServer(server, basic.NewVendorServer())
reflection.Register(server)
go func() {
listen, err := net.Listen("tcp", ":10002")
if err != nil {
global.GO_LOG.Sugar().Fatalf("net.Listen err: %v", err)
}
err = server.Serve(listen)
if err != nil {
global.GO_LOG.Sugar().Fatalf("server.Serve err: %v", err)
}
}()
}

View File

@ -14,5 +14,5 @@ type AuthRequest struct {
}
func (svc *Service) CheckAuth(param *AuthRequest) (model.Auth, error) {
return svc.dao.GetAuth(param.AppKey, param.AppSecret)
return svc.Dao.GetAuth(param.AppKey, param.AppSecret)
}

View File

@ -1,7 +1,7 @@
/*
* @Date: 2021-06-10 18:51:48
* @LastEditors: viletyy
* @LastEditTime: 2021-06-14 21:13:01
* @LastEditTime: 2021-06-16 23:58:59
* @FilePath: /potato/internal/service/service.go
*/
package service
@ -16,12 +16,12 @@ import (
type Service struct {
Ctx context.Context
dao *dao.Dao
Dao *dao.Dao
}
func New(ctx context.Context) Service {
svc := Service{Ctx: ctx}
svc.dao = dao.New(otgorm.WithContext(svc.Ctx, global.GO_DB))
svc.Dao = dao.New(otgorm.WithContext(svc.Ctx, global.GO_DB))
return svc
}

View File

@ -1,7 +1,7 @@
/*
* @Date: 2021-06-10 17:57:48
* @LastEditors: viletyy
* @LastEditTime: 2021-06-14 23:19:35
* @LastEditTime: 2021-06-16 23:59:12
* @FilePath: /potato/internal/service/vendor.go
*/
package service
@ -41,25 +41,25 @@ type DeleteVendorRequest struct {
}
func (svc *Service) CountVendor(param *CountVendorRequest) (int, error) {
return svc.dao.CountVendor(param.Name, param.Uuid)
return svc.Dao.CountVendor(param.Name, param.Uuid)
}
func (svc *Service) GetVendorList(param *VendorListRequest, pager *app.Pager) ([]basic.Vendor, error) {
return svc.dao.GetVendorList(param.Name, param.Uuid, pager.Page, pager.PageSize)
return svc.Dao.GetVendorList(param.Name, param.Uuid, pager.Page, pager.PageSize)
}
func (svc *Service) GetVendor(param *VendorRequest) (basic.Vendor, error) {
return svc.dao.GetVendor(param.ID)
return svc.Dao.GetVendor(param.ID)
}
func (svc *Service) CreateVendor(param *CreateVendorRequest) (basic.Vendor, error) {
return svc.dao.CreateVendor(param.Name, param.Uuid)
return svc.Dao.CreateVendor(param.Name, param.Uuid)
}
func (svc *Service) UpdateVendor(param *UpdateVendorRequest) (basic.Vendor, error) {
return svc.dao.UpdateVendor(param.ID, param.Name, param.Uuid)
return svc.Dao.UpdateVendor(param.ID, param.Name, param.Uuid)
}
func (svc *Service) DeleteVendor(param *DeleteVendorRequest) (basic.Vendor, error) {
return svc.dao.DeleteVendor(param.ID)
return svc.Dao.DeleteVendor(param.ID)
}

View File

@ -1,7 +1,7 @@
/*
* @Date: 2021-03-21 19:54:57
* @LastEditors: viletyy
* @LastEditTime: 2021-06-13 23:32:06
* @LastEditTime: 2021-06-17 00:29:41
* @FilePath: /potato/main.go
*/
package main
@ -26,6 +26,7 @@ func main() {
defer global.GO_DB.Close()
defer global.GO_REDIS.Close()
initialize.RunGrpc()
initialize.RunServer()
}

338
proto/basic/vendor.pb.go Normal file
View File

@ -0,0 +1,338 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.17.1
// source: proto/basic/vendor.proto
package basic
import (
proto "github.com/viletyy/potato/proto"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type GetVendorListRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
Uuid int64 `protobuf:"varint,2,opt,name=uuid,proto3" json:"uuid,omitempty"`
Page int64 `protobuf:"varint,3,opt,name=page,proto3" json:"page,omitempty"`
PageSize int64 `protobuf:"varint,4,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"`
}
func (x *GetVendorListRequest) Reset() {
*x = GetVendorListRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_basic_vendor_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *GetVendorListRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetVendorListRequest) ProtoMessage() {}
func (x *GetVendorListRequest) ProtoReflect() protoreflect.Message {
mi := &file_proto_basic_vendor_proto_msgTypes[0]
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 GetVendorListRequest.ProtoReflect.Descriptor instead.
func (*GetVendorListRequest) Descriptor() ([]byte, []int) {
return file_proto_basic_vendor_proto_rawDescGZIP(), []int{0}
}
func (x *GetVendorListRequest) GetName() string {
if x != nil {
return x.Name
}
return ""
}
func (x *GetVendorListRequest) GetUuid() int64 {
if x != nil {
return x.Uuid
}
return 0
}
func (x *GetVendorListRequest) GetPage() int64 {
if x != nil {
return x.Page
}
return 0
}
func (x *GetVendorListRequest) GetPageSize() int64 {
if x != nil {
return x.PageSize
}
return 0
}
type Vendor struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
Uuid int64 `protobuf:"varint,3,opt,name=uuid,proto3" json:"uuid,omitempty"`
}
func (x *Vendor) Reset() {
*x = Vendor{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_basic_vendor_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Vendor) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Vendor) ProtoMessage() {}
func (x *Vendor) ProtoReflect() protoreflect.Message {
mi := &file_proto_basic_vendor_proto_msgTypes[1]
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 Vendor.ProtoReflect.Descriptor instead.
func (*Vendor) Descriptor() ([]byte, []int) {
return file_proto_basic_vendor_proto_rawDescGZIP(), []int{1}
}
func (x *Vendor) GetId() int64 {
if x != nil {
return x.Id
}
return 0
}
func (x *Vendor) GetName() string {
if x != nil {
return x.Name
}
return ""
}
func (x *Vendor) GetUuid() int64 {
if x != nil {
return x.Uuid
}
return 0
}
type GetVendorListReply struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
List []*Vendor `protobuf:"bytes,1,rep,name=list,proto3" json:"list,omitempty"`
Pager *proto.Pager `protobuf:"bytes,2,opt,name=pager,proto3" json:"pager,omitempty"`
}
func (x *GetVendorListReply) Reset() {
*x = GetVendorListReply{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_basic_vendor_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *GetVendorListReply) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetVendorListReply) ProtoMessage() {}
func (x *GetVendorListReply) ProtoReflect() protoreflect.Message {
mi := &file_proto_basic_vendor_proto_msgTypes[2]
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 GetVendorListReply.ProtoReflect.Descriptor instead.
func (*GetVendorListReply) Descriptor() ([]byte, []int) {
return file_proto_basic_vendor_proto_rawDescGZIP(), []int{2}
}
func (x *GetVendorListReply) GetList() []*Vendor {
if x != nil {
return x.List
}
return nil
}
func (x *GetVendorListReply) GetPager() *proto.Pager {
if x != nil {
return x.Pager
}
return nil
}
var File_proto_basic_vendor_proto protoreflect.FileDescriptor
var file_proto_basic_vendor_proto_rawDesc = []byte{
0x0a, 0x18, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x62, 0x61, 0x73, 0x69, 0x63, 0x2f, 0x76, 0x65,
0x6e, 0x64, 0x6f, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x12, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x6f,
0x0a, 0x14, 0x47, 0x65, 0x74, 0x56, 0x65, 0x6e, 0x64, 0x6f, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01,
0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x75,
0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x75, 0x75, 0x69, 0x64, 0x12, 0x12,
0x0a, 0x04, 0x70, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x70, 0x61,
0x67, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x5f, 0x73, 0x69, 0x7a, 0x65, 0x18,
0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x22,
0x40, 0x0a, 0x06, 0x56, 0x65, 0x6e, 0x64, 0x6f, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18,
0x01, 0x20, 0x01, 0x28, 0x03, 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, 0x12, 0x0a,
0x04, 0x75, 0x75, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x75, 0x75, 0x69,
0x64, 0x22, 0x4f, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x56, 0x65, 0x6e, 0x64, 0x6f, 0x72, 0x4c, 0x69,
0x73, 0x74, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x1b, 0x0a, 0x04, 0x6c, 0x69, 0x73, 0x74, 0x18,
0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x07, 0x2e, 0x56, 0x65, 0x6e, 0x64, 0x6f, 0x72, 0x52, 0x04,
0x6c, 0x69, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x05, 0x70, 0x61, 0x67, 0x65, 0x72, 0x18, 0x02, 0x20,
0x01, 0x28, 0x0b, 0x32, 0x06, 0x2e, 0x50, 0x61, 0x67, 0x65, 0x72, 0x52, 0x05, 0x70, 0x61, 0x67,
0x65, 0x72, 0x32, 0x4e, 0x0a, 0x0d, 0x56, 0x65, 0x6e, 0x64, 0x6f, 0x72, 0x53, 0x65, 0x72, 0x76,
0x69, 0x63, 0x65, 0x12, 0x3d, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x56, 0x65, 0x6e, 0x64, 0x6f, 0x72,
0x4c, 0x69, 0x73, 0x74, 0x12, 0x15, 0x2e, 0x47, 0x65, 0x74, 0x56, 0x65, 0x6e, 0x64, 0x6f, 0x72,
0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x47, 0x65,
0x74, 0x56, 0x65, 0x6e, 0x64, 0x6f, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x70, 0x6c, 0x79,
0x22, 0x00, 0x42, 0x27, 0x5a, 0x25, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d,
0x2f, 0x76, 0x69, 0x6c, 0x65, 0x74, 0x79, 0x79, 0x2f, 0x70, 0x6f, 0x74, 0x61, 0x74, 0x6f, 0x2f,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x62, 0x61, 0x73, 0x69, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x33,
}
var (
file_proto_basic_vendor_proto_rawDescOnce sync.Once
file_proto_basic_vendor_proto_rawDescData = file_proto_basic_vendor_proto_rawDesc
)
func file_proto_basic_vendor_proto_rawDescGZIP() []byte {
file_proto_basic_vendor_proto_rawDescOnce.Do(func() {
file_proto_basic_vendor_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_basic_vendor_proto_rawDescData)
})
return file_proto_basic_vendor_proto_rawDescData
}
var file_proto_basic_vendor_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
var file_proto_basic_vendor_proto_goTypes = []interface{}{
(*GetVendorListRequest)(nil), // 0: GetVendorListRequest
(*Vendor)(nil), // 1: Vendor
(*GetVendorListReply)(nil), // 2: GetVendorListReply
(*proto.Pager)(nil), // 3: Pager
}
var file_proto_basic_vendor_proto_depIdxs = []int32{
1, // 0: GetVendorListReply.list:type_name -> Vendor
3, // 1: GetVendorListReply.pager:type_name -> Pager
0, // 2: VendorService.GetVendorList:input_type -> GetVendorListRequest
2, // 3: VendorService.GetVendorList:output_type -> GetVendorListReply
3, // [3:4] is the sub-list for method output_type
2, // [2:3] is the sub-list for method input_type
2, // [2:2] is the sub-list for extension type_name
2, // [2:2] is the sub-list for extension extendee
0, // [0:2] is the sub-list for field type_name
}
func init() { file_proto_basic_vendor_proto_init() }
func file_proto_basic_vendor_proto_init() {
if File_proto_basic_vendor_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_proto_basic_vendor_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GetVendorListRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_proto_basic_vendor_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Vendor); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_proto_basic_vendor_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GetVendorListReply); 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{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_proto_basic_vendor_proto_rawDesc,
NumEnums: 0,
NumMessages: 3,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_proto_basic_vendor_proto_goTypes,
DependencyIndexes: file_proto_basic_vendor_proto_depIdxs,
MessageInfos: file_proto_basic_vendor_proto_msgTypes,
}.Build()
File_proto_basic_vendor_proto = out.File
file_proto_basic_vendor_proto_rawDesc = nil
file_proto_basic_vendor_proto_goTypes = nil
file_proto_basic_vendor_proto_depIdxs = nil
}

27
proto/basic/vendor.proto Normal file
View File

@ -0,0 +1,27 @@
syntax = "proto3";
option go_package = "github.com/viletyy/potato/proto/basic";
import "proto/common.proto";
service VendorService {
rpc GetVendorList(GetVendorListRequest) returns (GetVendorListReply) {}
}
message GetVendorListRequest {
string name = 1;
int64 uuid = 2;
int64 page = 3;
int64 page_size = 4;
}
message Vendor {
int64 id = 1;
string name = 2;
int64 uuid = 3;
}
message GetVendorListReply {
repeated Vendor list = 1;
Pager pager = 2;
}

View File

@ -0,0 +1,101 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
package basic
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
// VendorServiceClient is the client API for VendorService service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type VendorServiceClient interface {
GetVendorList(ctx context.Context, in *GetVendorListRequest, opts ...grpc.CallOption) (*GetVendorListReply, error)
}
type vendorServiceClient struct {
cc grpc.ClientConnInterface
}
func NewVendorServiceClient(cc grpc.ClientConnInterface) VendorServiceClient {
return &vendorServiceClient{cc}
}
func (c *vendorServiceClient) GetVendorList(ctx context.Context, in *GetVendorListRequest, opts ...grpc.CallOption) (*GetVendorListReply, error) {
out := new(GetVendorListReply)
err := c.cc.Invoke(ctx, "/VendorService/GetVendorList", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// VendorServiceServer is the server API for VendorService service.
// All implementations must embed UnimplementedVendorServiceServer
// for forward compatibility
type VendorServiceServer interface {
GetVendorList(context.Context, *GetVendorListRequest) (*GetVendorListReply, error)
mustEmbedUnimplementedVendorServiceServer()
}
// UnimplementedVendorServiceServer must be embedded to have forward compatible implementations.
type UnimplementedVendorServiceServer struct {
}
func (UnimplementedVendorServiceServer) GetVendorList(context.Context, *GetVendorListRequest) (*GetVendorListReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetVendorList not implemented")
}
func (UnimplementedVendorServiceServer) mustEmbedUnimplementedVendorServiceServer() {}
// UnsafeVendorServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to VendorServiceServer will
// result in compilation errors.
type UnsafeVendorServiceServer interface {
mustEmbedUnimplementedVendorServiceServer()
}
func RegisterVendorServiceServer(s grpc.ServiceRegistrar, srv VendorServiceServer) {
s.RegisterService(&VendorService_ServiceDesc, srv)
}
func _VendorService_GetVendorList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetVendorListRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(VendorServiceServer).GetVendorList(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/VendorService/GetVendorList",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(VendorServiceServer).GetVendorList(ctx, req.(*GetVendorListRequest))
}
return interceptor(ctx, in, info, handler)
}
// VendorService_ServiceDesc is the grpc.ServiceDesc for VendorService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var VendorService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "VendorService",
HandlerType: (*VendorServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "GetVendorList",
Handler: _VendorService_GetVendorList_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "proto/basic/vendor.proto",
}

161
proto/common.pb.go Normal file
View File

@ -0,0 +1,161 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.17.1
// source: proto/common.proto
package proto
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type Pager struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Page int64 `protobuf:"varint,1,opt,name=page,proto3" json:"page,omitempty"`
PageSize int64 `protobuf:"varint,2,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"`
Total int64 `protobuf:"varint,3,opt,name=total,proto3" json:"total,omitempty"`
}
func (x *Pager) Reset() {
*x = Pager{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_common_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Pager) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Pager) ProtoMessage() {}
func (x *Pager) ProtoReflect() protoreflect.Message {
mi := &file_proto_common_proto_msgTypes[0]
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 Pager.ProtoReflect.Descriptor instead.
func (*Pager) Descriptor() ([]byte, []int) {
return file_proto_common_proto_rawDescGZIP(), []int{0}
}
func (x *Pager) GetPage() int64 {
if x != nil {
return x.Page
}
return 0
}
func (x *Pager) GetPageSize() int64 {
if x != nil {
return x.PageSize
}
return 0
}
func (x *Pager) GetTotal() int64 {
if x != nil {
return x.Total
}
return 0
}
var File_proto_common_proto protoreflect.FileDescriptor
var file_proto_common_proto_rawDesc = []byte{
0x0a, 0x12, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x22, 0x4e, 0x0a, 0x05, 0x50, 0x61, 0x67, 0x65, 0x72, 0x12, 0x12, 0x0a,
0x04, 0x70, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x70, 0x61, 0x67,
0x65, 0x12, 0x1b, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65, 0x5f, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x02,
0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x14,
0x0a, 0x05, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x74,
0x6f, 0x74, 0x61, 0x6c, 0x42, 0x21, 0x5a, 0x1f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63,
0x6f, 0x6d, 0x2f, 0x76, 0x69, 0x6c, 0x65, 0x74, 0x79, 0x79, 0x2f, 0x70, 0x6f, 0x74, 0x61, 0x74,
0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_proto_common_proto_rawDescOnce sync.Once
file_proto_common_proto_rawDescData = file_proto_common_proto_rawDesc
)
func file_proto_common_proto_rawDescGZIP() []byte {
file_proto_common_proto_rawDescOnce.Do(func() {
file_proto_common_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_common_proto_rawDescData)
})
return file_proto_common_proto_rawDescData
}
var file_proto_common_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_proto_common_proto_goTypes = []interface{}{
(*Pager)(nil), // 0: Pager
}
var file_proto_common_proto_depIdxs = []int32{
0, // [0:0] is the sub-list for method output_type
0, // [0:0] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_proto_common_proto_init() }
func file_proto_common_proto_init() {
if File_proto_common_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_proto_common_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Pager); 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{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_proto_common_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_proto_common_proto_goTypes,
DependencyIndexes: file_proto_common_proto_depIdxs,
MessageInfos: file_proto_common_proto_msgTypes,
}.Build()
File_proto_common_proto = out.File
file_proto_common_proto_rawDesc = nil
file_proto_common_proto_goTypes = nil
file_proto_common_proto_depIdxs = nil
}

9
proto/common.proto Normal file
View File

@ -0,0 +1,9 @@
syntax = "proto3";
option go_package= "github.com/viletyy/potato/proto";
message Pager {
int64 page = 1;
int64 page_size = 2;
int64 total = 3;
}

54
server/basic/vendor.go Normal file
View File

@ -0,0 +1,54 @@
/*
* @Date: 2021-06-16 23:49:02
* @LastEditors: viletyy
* @LastEditTime: 2021-06-17 00:18:47
* @FilePath: /potato/server/basic/vendor.go
*/
package basic
import (
"context"
"encoding/json"
"github.com/viletyy/potato/internal/service"
"github.com/viletyy/potato/pkg/app"
pb "github.com/viletyy/potato/proto/basic"
)
type VendorServer struct {
pb.UnimplementedVendorServiceServer
}
func NewVendorServer() *VendorServer {
return &VendorServer{}
}
func (t *VendorServer) GetVendorList(ctx context.Context, r *pb.GetVendorListRequest) (*pb.GetVendorListReply, error) {
svc := service.New(ctx)
dbVendorList, err := svc.Dao.GetVendorList(r.GetName(), int(r.GetUuid()), int(r.GetPage()), int(r.GetPageSize()))
if err != nil {
return nil, err
}
total, err := svc.Dao.CountVendor(r.GetName(), int(r.GetUuid()))
if err != nil {
return nil, err
}
data := map[string]interface{}{
"list": dbVendorList,
"pager": app.Pager{
Page: int(r.GetPage()),
PageSize: int(r.GetPageSize()),
Total: total,
},
}
byteData, err := json.Marshal(data)
if err != nil {
return nil, err
}
vendorList := pb.GetVendorListReply{}
err = json.Unmarshal(byteData, &vendorList)
if err != nil {
return nil, err
}
return &vendorList, nil
}