feat(完成m7s Rpc 测试): 完成m7s Rpc 测试

完成m7s Rpc 测试
This commit is contained in:
dabenxiong
2024-04-01 16:14:32 +08:00
parent 9a291e0883
commit 0b76799d6b
15 changed files with 553 additions and 218 deletions

1
go.mod
View File

@@ -3,6 +3,7 @@ module github.com/bigbeer1/m7sRpc
go 1.18
require (
github.com/jinzhu/copier v0.4.0
github.com/zeromicro/go-zero v1.4.2
google.golang.org/grpc v1.51.0
google.golang.org/protobuf v1.28.1

View File

@@ -1,48 +1,9 @@
package config
import (
"fmt"
"github.com/bigbeer1/m7sRpc/internal/server"
"github.com/bigbeer1/m7sRpc/internal/svc"
"github.com/bigbeer1/m7sRpc/m7sClient"
"github.com/zeromicro/go-zero/core/service"
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
. "m7s.live/engine/v4"
)
type RedisConfig struct {
type Config struct {
zrpc.RpcServerConf
Mysql struct {
DataSource string
}
CacheRedis cache.CacheConf
}
var plugin = InstallPlugin(&RedisConfig{})
func (c *RedisConfig) OnEvent(event any) {
switch event.(type) {
case FirstConfig:
ctx := svc.NewServiceContext(*c)
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
m7sClient.RegisterM7SServer(grpcServer, server.NewM7sServer(ctx))
if c.Mode == service.DevMode || c.Mode == service.TestMode {
reflection.Register(grpcServer)
}
})
defer s.Stop()
//rpc log
fmt.Println(c.Name, c.ListenOn)
s.Start()
}
}

View File

@@ -0,0 +1,31 @@
package logic
import (
"context"
"github.com/bigbeer1/m7sRpc/internal/svc"
"github.com/bigbeer1/m7sRpc/m7client"
"github.com/zeromicro/go-zero/core/logx"
)
type TestLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewTestLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TestLogic {
return &TestLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// 用户登录
func (l *TestLogic) Test(in *m7client.TestReq) (*m7client.TestResp, error) {
return &m7client.TestResp{
Message: in.Message + "11111",
}, nil
}

View File

@@ -0,0 +1,28 @@
// Code generated by goctl. DO NOT EDIT.
// Source: m7.proto
package server
import (
"context"
"github.com/bigbeer1/m7sRpc/internal/logic"
"github.com/bigbeer1/m7sRpc/internal/svc"
"github.com/bigbeer1/m7sRpc/m7client"
)
type M7Server struct {
svcCtx *svc.ServiceContext
m7client.UnimplementedM7Server
}
func NewM7Server(svcCtx *svc.ServiceContext) *M7Server {
return &M7Server{
svcCtx: svcCtx,
}
}
// 用户登录
func (s *M7Server) Test(ctx context.Context, in *m7client.TestReq) (*m7client.TestResp, error) {
l := logic.NewTestLogic(ctx, s.svcCtx)
return l.Test(in)
}

View File

@@ -1,18 +0,0 @@
// Code generated by goctl. DO NOT EDIT!
// Source: m7s.proto
package server
import (
"github.com/bigbeer1/m7sRpc/internal/svc"
)
type M7sServer struct {
svcCtx *svc.ServiceContext
}
func NewM7sServer(svcCtx *svc.ServiceContext) *M7sServer {
return &M7sServer{
svcCtx: svcCtx,
}
}

View File

@@ -5,10 +5,10 @@ import (
)
type ServiceContext struct {
Config config.RedisConfig
Config config.Config
}
func NewServiceContext(c config.RedisConfig) *ServiceContext {
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
}

32
m7.proto Normal file
View File

@@ -0,0 +1,32 @@
syntax = "proto3";
package m7client;
option go_package = "./m7client";
// 通用空返回
message CommonResp{
}
//SysUser start---------------------
message TestReq {
string message =1;
}
message TestResp {
string message =1;
}
service M7
{
// 用户登录
rpc Test(TestReq) returns (TestResp);
}

39
m7/m7.go Normal file
View File

@@ -0,0 +1,39 @@
// Code generated by goctl. DO NOT EDIT.
// Source: m7.proto
package m7
import (
"context"
"github.com/bigbeer1/m7sRpc/m7client"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
)
type (
CommonResp = m7client.CommonResp
TestReq = m7client.TestReq
TestResp = m7client.TestResp
M7 interface {
// 用户登录
Test(ctx context.Context, in *TestReq, opts ...grpc.CallOption) (*TestResp, error)
}
defaultM7 struct {
cli zrpc.Client
}
)
func NewM7(cli zrpc.Client) M7 {
return &defaultM7{
cli: cli,
}
}
// 用户登录
func (m *defaultM7) Test(ctx context.Context, in *TestReq, opts ...grpc.CallOption) (*TestResp, error) {
client := m7client.NewM7Client(m.cli.Conn())
return client.Test(ctx, in, opts...)
}

262
m7client/m7.pb.go Normal file
View File

@@ -0,0 +1,262 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.28.0
// protoc v3.19.4
// source: m7.proto
package m7client
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 CommonResp struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *CommonResp) Reset() {
*x = CommonResp{}
if protoimpl.UnsafeEnabled {
mi := &file_m7_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *CommonResp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*CommonResp) ProtoMessage() {}
func (x *CommonResp) ProtoReflect() protoreflect.Message {
mi := &file_m7_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 CommonResp.ProtoReflect.Descriptor instead.
func (*CommonResp) Descriptor() ([]byte, []int) {
return file_m7_proto_rawDescGZIP(), []int{0}
}
type TestReq struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
}
func (x *TestReq) Reset() {
*x = TestReq{}
if protoimpl.UnsafeEnabled {
mi := &file_m7_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *TestReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*TestReq) ProtoMessage() {}
func (x *TestReq) ProtoReflect() protoreflect.Message {
mi := &file_m7_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 TestReq.ProtoReflect.Descriptor instead.
func (*TestReq) Descriptor() ([]byte, []int) {
return file_m7_proto_rawDescGZIP(), []int{1}
}
func (x *TestReq) GetMessage() string {
if x != nil {
return x.Message
}
return ""
}
type TestResp struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
}
func (x *TestResp) Reset() {
*x = TestResp{}
if protoimpl.UnsafeEnabled {
mi := &file_m7_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *TestResp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*TestResp) ProtoMessage() {}
func (x *TestResp) ProtoReflect() protoreflect.Message {
mi := &file_m7_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 TestResp.ProtoReflect.Descriptor instead.
func (*TestResp) Descriptor() ([]byte, []int) {
return file_m7_proto_rawDescGZIP(), []int{2}
}
func (x *TestResp) GetMessage() string {
if x != nil {
return x.Message
}
return ""
}
var File_m7_proto protoreflect.FileDescriptor
var file_m7_proto_rawDesc = []byte{
0x0a, 0x08, 0x6d, 0x37, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x08, 0x6d, 0x37, 0x63, 0x6c,
0x69, 0x65, 0x6e, 0x74, 0x22, 0x0c, 0x0a, 0x0a, 0x43, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x52, 0x65,
0x73, 0x70, 0x22, 0x23, 0x0a, 0x07, 0x54, 0x65, 0x73, 0x74, 0x52, 0x65, 0x71, 0x12, 0x18, 0x0a,
0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07,
0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x24, 0x0a, 0x08, 0x54, 0x65, 0x73, 0x74, 0x52,
0x65, 0x73, 0x70, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01,
0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0x33, 0x0a,
0x02, 0x4d, 0x37, 0x12, 0x2d, 0x0a, 0x04, 0x54, 0x65, 0x73, 0x74, 0x12, 0x11, 0x2e, 0x6d, 0x37,
0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2e, 0x54, 0x65, 0x73, 0x74, 0x52, 0x65, 0x71, 0x1a, 0x12,
0x2e, 0x6d, 0x37, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2e, 0x54, 0x65, 0x73, 0x74, 0x52, 0x65,
0x73, 0x70, 0x42, 0x0c, 0x5a, 0x0a, 0x2e, 0x2f, 0x6d, 0x37, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74,
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_m7_proto_rawDescOnce sync.Once
file_m7_proto_rawDescData = file_m7_proto_rawDesc
)
func file_m7_proto_rawDescGZIP() []byte {
file_m7_proto_rawDescOnce.Do(func() {
file_m7_proto_rawDescData = protoimpl.X.CompressGZIP(file_m7_proto_rawDescData)
})
return file_m7_proto_rawDescData
}
var file_m7_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
var file_m7_proto_goTypes = []interface{}{
(*CommonResp)(nil), // 0: m7client.CommonResp
(*TestReq)(nil), // 1: m7client.TestReq
(*TestResp)(nil), // 2: m7client.TestResp
}
var file_m7_proto_depIdxs = []int32{
1, // 0: m7client.M7.Test:input_type -> m7client.TestReq
2, // 1: m7client.M7.Test:output_type -> m7client.TestResp
1, // [1:2] is the sub-list for method output_type
0, // [0:1] 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_m7_proto_init() }
func file_m7_proto_init() {
if File_m7_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_m7_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*CommonResp); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_m7_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*TestReq); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_m7_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*TestResp); 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_m7_proto_rawDesc,
NumEnums: 0,
NumMessages: 3,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_m7_proto_goTypes,
DependencyIndexes: file_m7_proto_depIdxs,
MessageInfos: file_m7_proto_msgTypes,
}.Build()
File_m7_proto = out.File
file_m7_proto_rawDesc = nil
file_m7_proto_goTypes = nil
file_m7_proto_depIdxs = nil
}

103
m7client/m7_grpc.pb.go Normal file
View File

@@ -0,0 +1,103 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
package m7client
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
// M7Client is the client API for M7 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 M7Client interface {
// 用户登录
Test(ctx context.Context, in *TestReq, opts ...grpc.CallOption) (*TestResp, error)
}
type m7Client struct {
cc grpc.ClientConnInterface
}
func NewM7Client(cc grpc.ClientConnInterface) M7Client {
return &m7Client{cc}
}
func (c *m7Client) Test(ctx context.Context, in *TestReq, opts ...grpc.CallOption) (*TestResp, error) {
out := new(TestResp)
err := c.cc.Invoke(ctx, "/m7client.M7/Test", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// M7Server is the server API for M7 service.
// All implementations must embed UnimplementedM7Server
// for forward compatibility
type M7Server interface {
// 用户登录
Test(context.Context, *TestReq) (*TestResp, error)
mustEmbedUnimplementedM7Server()
}
// UnimplementedM7Server must be embedded to have forward compatible implementations.
type UnimplementedM7Server struct {
}
func (UnimplementedM7Server) Test(context.Context, *TestReq) (*TestResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method Test not implemented")
}
func (UnimplementedM7Server) mustEmbedUnimplementedM7Server() {}
// UnsafeM7Server may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to M7Server will
// result in compilation errors.
type UnsafeM7Server interface {
mustEmbedUnimplementedM7Server()
}
func RegisterM7Server(s grpc.ServiceRegistrar, srv M7Server) {
s.RegisterService(&M7_ServiceDesc, srv)
}
func _M7_Test_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(TestReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(M7Server).Test(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/m7client.M7/Test",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(M7Server).Test(ctx, req.(*TestReq))
}
return interceptor(ctx, in, info, handler)
}
// M7_ServiceDesc is the grpc.ServiceDesc for M7 service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var M7_ServiceDesc = grpc.ServiceDesc{
ServiceName: "m7client.M7",
HandlerType: (*M7Server)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Test",
Handler: _M7_Test_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "m7.proto",
}

View File

@@ -1,11 +0,0 @@
syntax = "proto3";
package m7sClient;
option go_package = "./m7sClient";
service m7s {
}

View File

@@ -1,23 +0,0 @@
// Code generated by goctl. DO NOT EDIT!
// Source: m7s.proto
package m7s
import (
"github.com/zeromicro/go-zero/zrpc"
)
type (
M7s interface {
}
defaultM7s struct {
cli zrpc.Client
}
)
func NewM7s(cli zrpc.Client) M7s {
return &defaultM7s{
cli: cli,
}
}

View File

@@ -1,62 +0,0 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.28.0
// protoc v3.19.4
// source: m7s.proto
package m7sClient
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
)
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)
)
var File_m7s_proto protoreflect.FileDescriptor
var file_m7s_proto_rawDesc = []byte{
0x0a, 0x09, 0x6d, 0x37, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x09, 0x6d, 0x37, 0x73,
0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x32, 0x05, 0x0a, 0x03, 0x6d, 0x37, 0x73, 0x42, 0x0d, 0x5a,
0x0b, 0x2e, 0x2f, 0x6d, 0x37, 0x73, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x62, 0x06, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x33,
}
var file_m7s_proto_goTypes = []interface{}{}
var file_m7s_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_m7s_proto_init() }
func file_m7s_proto_init() {
if File_m7s_proto != nil {
return
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_m7s_proto_rawDesc,
NumEnums: 0,
NumMessages: 0,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_m7s_proto_goTypes,
DependencyIndexes: file_m7s_proto_depIdxs,
}.Build()
File_m7s_proto = out.File
file_m7s_proto_rawDesc = nil
file_m7s_proto_goTypes = nil
file_m7s_proto_depIdxs = nil
}

View File

@@ -1,62 +0,0 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
package m7sClient
import (
"github.com/bigbeer1/m7sRpc/internal/server"
grpc "google.golang.org/grpc"
)
// 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
// M7SClient is the client API for M7S 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 M7SClient interface {
}
type m7SClient struct {
cc grpc.ClientConnInterface
}
func NewM7SClient(cc grpc.ClientConnInterface) M7SClient {
return &m7SClient{cc}
}
// M7SServer is the server API for M7S service.
// All implementations must embed UnimplementedM7SServer
// for forward compatibility
type M7SServer interface {
mustEmbedUnimplementedM7SServer()
}
// UnimplementedM7SServer must be embedded to have forward compatible implementations.
type UnimplementedM7SServer struct {
}
func (UnimplementedM7SServer) mustEmbedUnimplementedM7SServer() {}
// UnsafeM7SServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to M7SServer will
// result in compilation errors.
type UnsafeM7SServer interface {
mustEmbedUnimplementedM7SServer()
}
func RegisterM7SServer(s grpc.ServiceRegistrar, srv *server.M7sServer) {
s.RegisterService(&M7S_ServiceDesc, srv)
}
// M7S_ServiceDesc is the grpc.ServiceDesc for M7S service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var M7S_ServiceDesc = grpc.ServiceDesc{
ServiceName: "m7sClient.m7s",
HandlerType: (*M7SServer)(nil),
Methods: []grpc.MethodDesc{},
Streams: []grpc.StreamDesc{},
Metadata: "m7s.proto",
}

54
main.go
View File

@@ -1 +1,55 @@
package m7sRpc
import (
"fmt"
"github.com/bigbeer1/m7sRpc/internal/config"
"github.com/bigbeer1/m7sRpc/internal/server"
"github.com/bigbeer1/m7sRpc/internal/svc"
"github.com/bigbeer1/m7sRpc/m7client"
"github.com/jinzhu/copier"
"github.com/zeromicro/go-zero/core/service"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
. "m7s.live/engine/v4"
"time"
)
type M7sRpcConfig struct {
Name string
ListenOn string
Timeout int64 `json:",default=2000"`
}
var plugin = InstallPlugin(&M7sRpcConfig{})
func (m M7sRpcConfig) OnEvent(event any) {
fmt.Println("6666666666")
switch event.(type) {
case FirstConfig:
var c config.Config
_ = copier.Copy(&c, m)
ctx := svc.NewServiceContext(c)
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
m7client.RegisterM7Server(grpcServer, server.NewM7Server(ctx))
if c.Mode == service.DevMode || c.Mode == service.TestMode {
reflection.Register(grpcServer)
}
})
defer s.Stop()
// 设置日志输出 接口慢时间 rpc
zrpc.SetServerSlowThreshold(time.Second * 2000)
//rpc log
//s.AddUnaryInterceptors(rpcserver.LoggerInterceptor)
fmt.Println(c.Name, c.ListenOn)
s.Start()
}
}