diff --git a/.gitea/workflows/dev.yaml b/.gitea/workflows/dev.yaml index 17781cb..582b220 100644 --- a/.gitea/workflows/dev.yaml +++ b/.gitea/workflows/dev.yaml @@ -41,4 +41,4 @@ jobs: COMPOSE_PROJECT_NAME: youtu_grpc - name: clean up run: | - docker rmi $(docker images -f "dangling=true" -q) + docker system prune -f diff --git a/app/admin_service/admin_service.proto b/app/admin_service/admin_service.proto index 4c9ce5b..ca766db 100644 --- a/app/admin_service/admin_service.proto +++ b/app/admin_service/admin_service.proto @@ -22,7 +22,7 @@ message GetAppListResponse { message AppInfo { int32 id = 1; - string type = 2; + int32 type = 2; string app_id = 3; string secret = 4; string remark = 5; @@ -46,6 +46,14 @@ message AddAppResponse { bool success = 1; } +message CoverAppRequest { + repeated AppInfo app_info = 1; +} + +message CoverAppResponse { + bool success = 1; +} + service admin_service { rpc Ping(Request) returns(Response); // 获取app列表 @@ -59,4 +67,7 @@ service admin_service { // AddApp 添加app rpc AddApp(AddAppRequest) returns(AddAppResponse); + + // 覆盖app数据 + rpc CoverApp(CoverAppRequest) returns(CoverAppResponse); } diff --git a/app/admin_service/admin_service/admin_service.pb.go b/app/admin_service/admin_service/admin_service.pb.go index 3e685d5..54a50f3 100644 --- a/app/admin_service/admin_service/admin_service.pb.go +++ b/app/admin_service/admin_service/admin_service.pb.go @@ -192,7 +192,7 @@ func (x *GetAppListResponse) GetAppList() []*AppInfo { type AppInfo struct { state protoimpl.MessageState `protogen:"open.v1"` Id int32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` - Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"` + Type int32 `protobuf:"varint,2,opt,name=type,proto3" json:"type,omitempty"` AppId string `protobuf:"bytes,3,opt,name=app_id,json=appId,proto3" json:"app_id,omitempty"` Secret string `protobuf:"bytes,4,opt,name=secret,proto3" json:"secret,omitempty"` Remark string `protobuf:"bytes,5,opt,name=remark,proto3" json:"remark,omitempty"` @@ -239,11 +239,11 @@ func (x *AppInfo) GetId() int32 { return 0 } -func (x *AppInfo) GetType() string { +func (x *AppInfo) GetType() int32 { if x != nil { return x.Type } - return "" + return 0 } func (x *AppInfo) GetAppId() string { @@ -457,6 +457,94 @@ func (x *AddAppResponse) GetSuccess() bool { return false } +type CoverAppRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + AppInfo []*AppInfo `protobuf:"bytes,1,rep,name=app_info,json=appInfo,proto3" json:"app_info,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *CoverAppRequest) Reset() { + *x = CoverAppRequest{} + mi := &file_admin_service_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *CoverAppRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CoverAppRequest) ProtoMessage() {} + +func (x *CoverAppRequest) ProtoReflect() protoreflect.Message { + mi := &file_admin_service_proto_msgTypes[9] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CoverAppRequest.ProtoReflect.Descriptor instead. +func (*CoverAppRequest) Descriptor() ([]byte, []int) { + return file_admin_service_proto_rawDescGZIP(), []int{9} +} + +func (x *CoverAppRequest) GetAppInfo() []*AppInfo { + if x != nil { + return x.AppInfo + } + return nil +} + +type CoverAppResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + Success bool `protobuf:"varint,1,opt,name=success,proto3" json:"success,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *CoverAppResponse) Reset() { + *x = CoverAppResponse{} + mi := &file_admin_service_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *CoverAppResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CoverAppResponse) ProtoMessage() {} + +func (x *CoverAppResponse) ProtoReflect() protoreflect.Message { + mi := &file_admin_service_proto_msgTypes[10] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CoverAppResponse.ProtoReflect.Descriptor instead. +func (*CoverAppResponse) Descriptor() ([]byte, []int) { + return file_admin_service_proto_rawDescGZIP(), []int{10} +} + +func (x *CoverAppResponse) GetSuccess() bool { + if x != nil { + return x.Success + } + return false +} + var File_admin_service_proto protoreflect.FileDescriptor var file_admin_service_proto_rawDesc = string([]byte{ @@ -474,7 +562,7 @@ var file_admin_service_proto_rawDesc = string([]byte{ 0x2e, 0x41, 0x70, 0x70, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x07, 0x61, 0x70, 0x70, 0x4c, 0x69, 0x73, 0x74, 0x22, 0x9a, 0x01, 0x0a, 0x07, 0x41, 0x70, 0x70, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, - 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, + 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x15, 0x0a, 0x06, 0x61, 0x70, 0x70, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, @@ -494,32 +582,44 @@ var file_admin_service_proto_rawDesc = string([]byte{ 0x52, 0x07, 0x61, 0x70, 0x70, 0x49, 0x6e, 0x66, 0x6f, 0x22, 0x2a, 0x0a, 0x0e, 0x41, 0x64, 0x64, 0x41, 0x70, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x73, 0x75, - 0x63, 0x63, 0x65, 0x73, 0x73, 0x32, 0xf3, 0x02, 0x0a, 0x0d, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x5f, - 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x37, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, - 0x16, 0x2e, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x5f, - 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x12, 0x51, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x41, 0x70, 0x70, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x20, - 0x2e, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x47, - 0x65, 0x74, 0x41, 0x70, 0x70, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x21, 0x2e, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, - 0x2e, 0x47, 0x65, 0x74, 0x41, 0x70, 0x70, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x12, 0x42, 0x0a, 0x09, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4f, 0x6e, 0x65, - 0x12, 0x16, 0x2e, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, - 0x2e, 0x41, 0x70, 0x70, 0x49, 0x6e, 0x66, 0x6f, 0x1a, 0x1d, 0x2e, 0x61, 0x64, 0x6d, 0x69, 0x6e, - 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4b, 0x0a, 0x09, 0x44, 0x65, 0x6c, 0x65, 0x74, - 0x65, 0x41, 0x70, 0x70, 0x12, 0x1f, 0x2e, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x65, 0x72, - 0x76, 0x69, 0x63, 0x65, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x70, 0x70, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x65, - 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x45, 0x0a, 0x06, 0x41, 0x64, 0x64, 0x41, 0x70, 0x70, 0x12, 0x1c, - 0x2e, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x41, - 0x64, 0x64, 0x41, 0x70, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x61, - 0x64, 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x41, 0x64, 0x64, - 0x41, 0x70, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x11, 0x5a, 0x0f, 0x2e, - 0x2f, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x62, 0x06, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x63, 0x63, 0x65, 0x73, 0x73, 0x22, 0x44, 0x0a, 0x0f, 0x43, 0x6f, 0x76, 0x65, 0x72, 0x41, 0x70, + 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x31, 0x0a, 0x08, 0x61, 0x70, 0x70, 0x5f, + 0x69, 0x6e, 0x66, 0x6f, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x61, 0x64, 0x6d, + 0x69, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x41, 0x70, 0x70, 0x49, 0x6e, + 0x66, 0x6f, 0x52, 0x07, 0x61, 0x70, 0x70, 0x49, 0x6e, 0x66, 0x6f, 0x22, 0x2c, 0x0a, 0x10, 0x43, + 0x6f, 0x76, 0x65, 0x72, 0x41, 0x70, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, + 0x18, 0x0a, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, + 0x52, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x32, 0xc0, 0x03, 0x0a, 0x0d, 0x61, 0x64, + 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x37, 0x0a, 0x04, 0x50, + 0x69, 0x6e, 0x67, 0x12, 0x16, 0x2e, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x61, 0x64, + 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x51, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x41, 0x70, 0x70, 0x4c, 0x69, + 0x73, 0x74, 0x12, 0x20, 0x2e, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x70, 0x70, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x65, 0x72, + 0x76, 0x69, 0x63, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x70, 0x70, 0x4c, 0x69, 0x73, 0x74, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x42, 0x0a, 0x09, 0x55, 0x70, 0x64, 0x61, 0x74, + 0x65, 0x4f, 0x6e, 0x65, 0x12, 0x16, 0x2e, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x65, 0x72, + 0x76, 0x69, 0x63, 0x65, 0x2e, 0x41, 0x70, 0x70, 0x49, 0x6e, 0x66, 0x6f, 0x1a, 0x1d, 0x2e, 0x61, + 0x64, 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x43, 0x6f, 0x6d, + 0x6d, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4b, 0x0a, 0x09, 0x44, + 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x70, 0x70, 0x12, 0x1f, 0x2e, 0x61, 0x64, 0x6d, 0x69, 0x6e, + 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, + 0x70, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x61, 0x64, 0x6d, 0x69, + 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x45, 0x0a, 0x06, 0x41, 0x64, 0x64, 0x41, + 0x70, 0x70, 0x12, 0x1c, 0x2e, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x2e, 0x41, 0x64, 0x64, 0x41, 0x70, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x1d, 0x2e, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x2e, 0x41, 0x64, 0x64, 0x41, 0x70, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, + 0x4b, 0x0a, 0x08, 0x43, 0x6f, 0x76, 0x65, 0x72, 0x41, 0x70, 0x70, 0x12, 0x1e, 0x2e, 0x61, 0x64, + 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x43, 0x6f, 0x76, 0x65, + 0x72, 0x41, 0x70, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x61, 0x64, + 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x43, 0x6f, 0x76, 0x65, + 0x72, 0x41, 0x70, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x11, 0x5a, 0x0f, + 0x2e, 0x2f, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, }) var ( @@ -534,7 +634,7 @@ func file_admin_service_proto_rawDescGZIP() []byte { return file_admin_service_proto_rawDescData } -var file_admin_service_proto_msgTypes = make([]protoimpl.MessageInfo, 9) +var file_admin_service_proto_msgTypes = make([]protoimpl.MessageInfo, 11) var file_admin_service_proto_goTypes = []any{ (*Request)(nil), // 0: admin_service.Request (*Response)(nil), // 1: admin_service.Response @@ -545,25 +645,30 @@ var file_admin_service_proto_goTypes = []any{ (*DeleteAppRequest)(nil), // 6: admin_service.DeleteAppRequest (*AddAppRequest)(nil), // 7: admin_service.AddAppRequest (*AddAppResponse)(nil), // 8: admin_service.AddAppResponse + (*CoverAppRequest)(nil), // 9: admin_service.CoverAppRequest + (*CoverAppResponse)(nil), // 10: admin_service.CoverAppResponse } var file_admin_service_proto_depIdxs = []int32{ - 4, // 0: admin_service.GetAppListResponse.app_list:type_name -> admin_service.AppInfo - 4, // 1: admin_service.AddAppRequest.app_info:type_name -> admin_service.AppInfo - 0, // 2: admin_service.admin_service.Ping:input_type -> admin_service.Request - 2, // 3: admin_service.admin_service.GetAppList:input_type -> admin_service.GetAppListRequest - 4, // 4: admin_service.admin_service.UpdateOne:input_type -> admin_service.AppInfo - 6, // 5: admin_service.admin_service.DeleteApp:input_type -> admin_service.DeleteAppRequest - 7, // 6: admin_service.admin_service.AddApp:input_type -> admin_service.AddAppRequest - 1, // 7: admin_service.admin_service.Ping:output_type -> admin_service.Response - 3, // 8: admin_service.admin_service.GetAppList:output_type -> admin_service.GetAppListResponse - 5, // 9: admin_service.admin_service.UpdateOne:output_type -> admin_service.CommonResponse - 5, // 10: admin_service.admin_service.DeleteApp:output_type -> admin_service.CommonResponse - 8, // 11: admin_service.admin_service.AddApp:output_type -> admin_service.AddAppResponse - 7, // [7:12] is the sub-list for method output_type - 2, // [2:7] 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 + 4, // 0: admin_service.GetAppListResponse.app_list:type_name -> admin_service.AppInfo + 4, // 1: admin_service.AddAppRequest.app_info:type_name -> admin_service.AppInfo + 4, // 2: admin_service.CoverAppRequest.app_info:type_name -> admin_service.AppInfo + 0, // 3: admin_service.admin_service.Ping:input_type -> admin_service.Request + 2, // 4: admin_service.admin_service.GetAppList:input_type -> admin_service.GetAppListRequest + 4, // 5: admin_service.admin_service.UpdateOne:input_type -> admin_service.AppInfo + 6, // 6: admin_service.admin_service.DeleteApp:input_type -> admin_service.DeleteAppRequest + 7, // 7: admin_service.admin_service.AddApp:input_type -> admin_service.AddAppRequest + 9, // 8: admin_service.admin_service.CoverApp:input_type -> admin_service.CoverAppRequest + 1, // 9: admin_service.admin_service.Ping:output_type -> admin_service.Response + 3, // 10: admin_service.admin_service.GetAppList:output_type -> admin_service.GetAppListResponse + 5, // 11: admin_service.admin_service.UpdateOne:output_type -> admin_service.CommonResponse + 5, // 12: admin_service.admin_service.DeleteApp:output_type -> admin_service.CommonResponse + 8, // 13: admin_service.admin_service.AddApp:output_type -> admin_service.AddAppResponse + 10, // 14: admin_service.admin_service.CoverApp:output_type -> admin_service.CoverAppResponse + 9, // [9:15] is the sub-list for method output_type + 3, // [3:9] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name } func init() { file_admin_service_proto_init() } @@ -577,7 +682,7 @@ func file_admin_service_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_admin_service_proto_rawDesc), len(file_admin_service_proto_rawDesc)), NumEnums: 0, - NumMessages: 9, + NumMessages: 11, NumExtensions: 0, NumServices: 1, }, diff --git a/app/admin_service/admin_service/admin_service_grpc.pb.go b/app/admin_service/admin_service/admin_service_grpc.pb.go index db7e743..fb38a5d 100644 --- a/app/admin_service/admin_service/admin_service_grpc.pb.go +++ b/app/admin_service/admin_service/admin_service_grpc.pb.go @@ -24,6 +24,7 @@ const ( AdminService_UpdateOne_FullMethodName = "/admin_service.admin_service/UpdateOne" AdminService_DeleteApp_FullMethodName = "/admin_service.admin_service/DeleteApp" AdminService_AddApp_FullMethodName = "/admin_service.admin_service/AddApp" + AdminService_CoverApp_FullMethodName = "/admin_service.admin_service/CoverApp" ) // AdminServiceClient is the client API for AdminService service. @@ -33,12 +34,14 @@ type AdminServiceClient interface { Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) // 获取app列表 GetAppList(ctx context.Context, in *GetAppListRequest, opts ...grpc.CallOption) (*GetAppListResponse, error) - // 修改app列表 + // UpdateOne 修改app数据 UpdateOne(ctx context.Context, in *AppInfo, opts ...grpc.CallOption) (*CommonResponse, error) - // 删除app + // DeleteApp 删除app DeleteApp(ctx context.Context, in *DeleteAppRequest, opts ...grpc.CallOption) (*CommonResponse, error) - // 添加app + // AddApp 添加app AddApp(ctx context.Context, in *AddAppRequest, opts ...grpc.CallOption) (*AddAppResponse, error) + // 覆盖app数据 + CoverApp(ctx context.Context, in *CoverAppRequest, opts ...grpc.CallOption) (*CoverAppResponse, error) } type adminServiceClient struct { @@ -99,6 +102,16 @@ func (c *adminServiceClient) AddApp(ctx context.Context, in *AddAppRequest, opts return out, nil } +func (c *adminServiceClient) CoverApp(ctx context.Context, in *CoverAppRequest, opts ...grpc.CallOption) (*CoverAppResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(CoverAppResponse) + err := c.cc.Invoke(ctx, AdminService_CoverApp_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + // AdminServiceServer is the server API for AdminService service. // All implementations must embed UnimplementedAdminServiceServer // for forward compatibility. @@ -106,12 +119,14 @@ type AdminServiceServer interface { Ping(context.Context, *Request) (*Response, error) // 获取app列表 GetAppList(context.Context, *GetAppListRequest) (*GetAppListResponse, error) - // 修改app列表 + // UpdateOne 修改app数据 UpdateOne(context.Context, *AppInfo) (*CommonResponse, error) - // 删除app + // DeleteApp 删除app DeleteApp(context.Context, *DeleteAppRequest) (*CommonResponse, error) - // 添加app + // AddApp 添加app AddApp(context.Context, *AddAppRequest) (*AddAppResponse, error) + // 覆盖app数据 + CoverApp(context.Context, *CoverAppRequest) (*CoverAppResponse, error) mustEmbedUnimplementedAdminServiceServer() } @@ -137,6 +152,9 @@ func (UnimplementedAdminServiceServer) DeleteApp(context.Context, *DeleteAppRequ func (UnimplementedAdminServiceServer) AddApp(context.Context, *AddAppRequest) (*AddAppResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method AddApp not implemented") } +func (UnimplementedAdminServiceServer) CoverApp(context.Context, *CoverAppRequest) (*CoverAppResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CoverApp not implemented") +} func (UnimplementedAdminServiceServer) mustEmbedUnimplementedAdminServiceServer() {} func (UnimplementedAdminServiceServer) testEmbeddedByValue() {} @@ -248,6 +266,24 @@ func _AdminService_AddApp_Handler(srv interface{}, ctx context.Context, dec func return interceptor(ctx, in, info, handler) } +func _AdminService_CoverApp_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CoverAppRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AdminServiceServer).CoverApp(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: AdminService_CoverApp_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AdminServiceServer).CoverApp(ctx, req.(*CoverAppRequest)) + } + return interceptor(ctx, in, info, handler) +} + // AdminService_ServiceDesc is the grpc.ServiceDesc for AdminService service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -275,6 +311,10 @@ var AdminService_ServiceDesc = grpc.ServiceDesc{ MethodName: "AddApp", Handler: _AdminService_AddApp_Handler, }, + { + MethodName: "CoverApp", + Handler: _AdminService_CoverApp_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "admin_service.proto", diff --git a/app/admin_service/admin_service_client/admin_service.go b/app/admin_service/admin_service_client/admin_service.go index 1d671cc..d429049 100644 --- a/app/admin_service/admin_service_client/admin_service.go +++ b/app/admin_service/admin_service_client/admin_service.go @@ -18,6 +18,8 @@ type ( AddAppResponse = admin_service.AddAppResponse AppInfo = admin_service.AppInfo CommonResponse = admin_service.CommonResponse + CoverAppRequest = admin_service.CoverAppRequest + CoverAppResponse = admin_service.CoverAppResponse DeleteAppRequest = admin_service.DeleteAppRequest GetAppListRequest = admin_service.GetAppListRequest GetAppListResponse = admin_service.GetAppListResponse @@ -28,12 +30,14 @@ type ( Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) // 获取app列表 GetAppList(ctx context.Context, in *GetAppListRequest, opts ...grpc.CallOption) (*GetAppListResponse, error) - // 修改app列表 + // UpdateOne 修改app数据 UpdateOne(ctx context.Context, in *AppInfo, opts ...grpc.CallOption) (*CommonResponse, error) - // 删除app + // DeleteApp 删除app DeleteApp(ctx context.Context, in *DeleteAppRequest, opts ...grpc.CallOption) (*CommonResponse, error) - // 添加app + // AddApp 添加app AddApp(ctx context.Context, in *AddAppRequest, opts ...grpc.CallOption) (*AddAppResponse, error) + // 覆盖app数据 + CoverApp(ctx context.Context, in *CoverAppRequest, opts ...grpc.CallOption) (*CoverAppResponse, error) } defaultAdminService struct { @@ -58,20 +62,26 @@ func (m *defaultAdminService) GetAppList(ctx context.Context, in *GetAppListRequ return client.GetAppList(ctx, in, opts...) } -// 修改app列表 +// UpdateOne 修改app数据 func (m *defaultAdminService) UpdateOne(ctx context.Context, in *AppInfo, opts ...grpc.CallOption) (*CommonResponse, error) { client := admin_service.NewAdminServiceClient(m.cli.Conn()) return client.UpdateOne(ctx, in, opts...) } -// 删除app +// DeleteApp 删除app func (m *defaultAdminService) DeleteApp(ctx context.Context, in *DeleteAppRequest, opts ...grpc.CallOption) (*CommonResponse, error) { client := admin_service.NewAdminServiceClient(m.cli.Conn()) return client.DeleteApp(ctx, in, opts...) } -// 添加app +// AddApp 添加app func (m *defaultAdminService) AddApp(ctx context.Context, in *AddAppRequest, opts ...grpc.CallOption) (*AddAppResponse, error) { client := admin_service.NewAdminServiceClient(m.cli.Conn()) return client.AddApp(ctx, in, opts...) } + +// 覆盖app数据 +func (m *defaultAdminService) CoverApp(ctx context.Context, in *CoverAppRequest, opts ...grpc.CallOption) (*CoverAppResponse, error) { + client := admin_service.NewAdminServiceClient(m.cli.Conn()) + return client.CoverApp(ctx, in, opts...) +} diff --git a/app/admin_service/internal/logic/cover_app_logic.go b/app/admin_service/internal/logic/cover_app_logic.go new file mode 100644 index 0000000..17ae71b --- /dev/null +++ b/app/admin_service/internal/logic/cover_app_logic.go @@ -0,0 +1,36 @@ +package logic + +import ( + "context" + + "gitea.youtukeji.com.cn/youtu/youtu_grpc/app/admin_service/admin_service" + "gitea.youtukeji.com.cn/youtu/youtu_grpc/app/admin_service/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type CoverAppLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewCoverAppLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CoverAppLogic { + return &CoverAppLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// CoverApp 覆盖app数据 +func (l *CoverAppLogic) CoverApp(in *admin_service.CoverAppRequest) (*admin_service.CoverAppResponse, error) { + // 删除所有app数据 + l.svcCtx.Cached.DeleteAllFromEtcd(l.ctx) + // 添加新数据 + for _, app := range in.AppInfo { + l.svcCtx.Cached.PutToEtcd(l.ctx, app) + } + + return &admin_service.CoverAppResponse{}, nil +} diff --git a/app/admin_service/internal/server/admin_service_server.go b/app/admin_service/internal/server/admin_service_server.go index 4c6e4d4..9755558 100644 --- a/app/admin_service/internal/server/admin_service_server.go +++ b/app/admin_service/internal/server/admin_service_server.go @@ -34,20 +34,26 @@ func (s *AdminServiceServer) GetAppList(ctx context.Context, in *admin_service.G return l.GetAppList(in) } -// 修改app列表 +// UpdateOne 修改app数据 func (s *AdminServiceServer) UpdateOne(ctx context.Context, in *admin_service.AppInfo) (*admin_service.CommonResponse, error) { l := logic.NewUpdateOneLogic(ctx, s.svcCtx) return l.UpdateOne(in) } -// 删除app +// DeleteApp 删除app func (s *AdminServiceServer) DeleteApp(ctx context.Context, in *admin_service.DeleteAppRequest) (*admin_service.CommonResponse, error) { l := logic.NewDeleteAppLogic(ctx, s.svcCtx) return l.DeleteApp(in) } -// 添加app +// AddApp 添加app func (s *AdminServiceServer) AddApp(ctx context.Context, in *admin_service.AddAppRequest) (*admin_service.AddAppResponse, error) { l := logic.NewAddAppLogic(ctx, s.svcCtx) return l.AddApp(in) } + +// 覆盖app数据 +func (s *AdminServiceServer) CoverApp(ctx context.Context, in *admin_service.CoverAppRequest) (*admin_service.CoverAppResponse, error) { + l := logic.NewCoverAppLogic(ctx, s.svcCtx) + return l.CoverApp(in) +} diff --git a/app/admin_service/internal/svc/app_data.go b/app/admin_service/internal/svc/app_data.go index 17e2f42..1d41c8a 100644 --- a/app/admin_service/internal/svc/app_data.go +++ b/app/admin_service/internal/svc/app_data.go @@ -16,7 +16,7 @@ import ( // EcpmConfig 定义数据结构 type EcpmConfig struct { - AppID string `json:"appId"` + AppID string `json:"appId,omitempty"` ECPM float32 `json:"eCPM"` IPU uint32 `json:"IPU"` } @@ -25,7 +25,7 @@ type EcpmConfig struct { type AppData struct { AppID string `json:"appId,omitempty"` AppSecret string `json:"appSecret"` - Type string `json:"type"` + Type int32 `json:"type"` Remark string `json:"remark"` } @@ -266,6 +266,12 @@ func (data *AppDataCache) DeleteFromEtcd(ctx context.Context, key string) { _, _ = data.client.Delete(ctx, ecpmDataKey+key) } +// DeleteAllFromEtcd 从etcd删除 +func (data *AppDataCache) DeleteAllFromEtcd(ctx context.Context) { + _, _ = data.client.Delete(ctx, appDataKey, clientv3.WithPrefix()) + _, _ = data.client.Delete(ctx, ecpmDataKey, clientv3.WithPrefix()) +} + // PutToEtcd 向etcd写入 func (data *AppDataCache) PutToEtcd(ctx context.Context, appInfo *admin_service.AppInfo) { appData := &AppData{ diff --git a/app/auth_service/internal/config/config.go b/app/auth_service/internal/config/config.go index 0529adc..d912156 100644 --- a/app/auth_service/internal/config/config.go +++ b/app/auth_service/internal/config/config.go @@ -1,12 +1 @@ package config - -import "github.com/zeromicro/go-zero/zrpc" - -type Config struct { - zrpc.RpcServerConf - AppData []struct { - AppId string - AppSecret string - Type string - } -} diff --git a/app/auth_service/internal/svc/service_context.go b/app/auth_service/internal/svc/service_context.go index 05cb8d3..43bfb64 100644 --- a/app/auth_service/internal/svc/service_context.go +++ b/app/auth_service/internal/svc/service_context.go @@ -68,7 +68,7 @@ func NewServiceContext(c config.Config) *ServiceContext { type AppData struct { AppId string `json:"appId"` AppSecret string `json:"appSecret"` - Type string `json:"type"` + Type int32 `json:"type"` } type AppDataList []AppData diff --git a/app/auth_service/pkg/cli.go b/app/auth_service/pkg/cli.go index e6a580d..8626035 100644 --- a/app/auth_service/pkg/cli.go +++ b/app/auth_service/pkg/cli.go @@ -7,8 +7,8 @@ import ( ) const ( - DouyinClientType = "douyin" - WechatClientType = "wechat" + DouyinClientType = iota + WechatClientType ) var ( diff --git a/app/ecpm_service/internal/svc/service_context.go b/app/ecpm_service/internal/svc/service_context.go index 4d1f10a..aef158e 100644 --- a/app/ecpm_service/internal/svc/service_context.go +++ b/app/ecpm_service/internal/svc/service_context.go @@ -48,9 +48,11 @@ func (svc *ServiceContext) initEtcd() { ch := make(chan config.WatchKV) go config.EtcdGetOneAndWatch(context.Background(), cli, EcpmConfigWatchKey, ch) - for res := range ch { - svc.EcpmConfig.SetAllByJson(strings.TrimPrefix(res.Key, EcpmConfigWatchKey), res.Value) - } + go func() { + for res := range ch { + svc.EcpmConfig.SetAllByJson(strings.TrimPrefix(res.Key, EcpmConfigWatchKey), res.Value) + } + }() svc.etcdCli = cli } diff --git a/pkg/config/get_config.go b/pkg/config/get_config.go index f4bac82..54f154e 100644 --- a/pkg/config/get_config.go +++ b/pkg/config/get_config.go @@ -8,6 +8,7 @@ import ( "github.com/zeromicro/go-zero/zrpc" "go.etcd.io/etcd/api/v3/mvccpb" clientv3 "go.etcd.io/etcd/client/v3" + "log" "os" ) @@ -60,11 +61,29 @@ func GetConfig(c *Config, serverName string) (err error) { if err != nil { return } + + // 读取公共配置并合并 + serviceConfig := viper.New() + err = serviceConfig.AddRemoteProvider("etcd3", viper.GetString(EtcdAddrKey), Prefix+"common.rpc") + if err != nil { + log.Fatalf("Failed to read service config: %v", err) + return err + } + serviceConfig.SetConfigType("json") + if err := serviceConfig.ReadRemoteConfig(); err != nil { + log.Fatalf("Failed to read service config: %v", err) + } + err = viper.MergeConfigMap(serviceConfig.AllSettings()) + if err != nil { + return err + } + err = viper.Unmarshal(&c) if err != nil { return } c.RpcServerConf.Name = serverName + ".rpc" + c.RpcServerConf.Etcd.Key = serverName + ".rpc" c.RpcServerConf.ServiceConf.Mode = c.Mode return }