فهرست منبع

feat:删除oss文件、log日志增加

zhangxinlei1996 1 سال پیش
والد
کامیت
b872b8b3d8
6فایلهای تغییر یافته به همراه77 افزوده شده و 14 حذف شده
  1. 3 3
      entity/oss.go
  2. 2 1
      rpc/fileCenter.proto
  3. 22 0
      rpc/filecenter.go
  4. 10 0
      rpc/internal/config/config.go
  5. 11 2
      rpc/internal/logic/deletelogic.go
  6. 29 8
      rpc/pb/fileCenter.pb.go

+ 3 - 3
entity/oss.go

@@ -25,7 +25,7 @@ func OssInit(ossEndpoint, ossAccessKeyID, ossAccessKeySecret string) {
 
 // OssPutObject oss附件上传
 func OssPutObject(objectName string, fd io.Reader, ossBucketName string) (bool, error) {
-	common.Catch()
+	defer common.Catch()
 	// 获取存储空间。
 	bucket, err := Ossclient.Bucket(ossBucketName)
 	if err != nil {
@@ -49,7 +49,7 @@ func OssPutObject(objectName string, fd io.Reader, ossBucketName string) (bool,
 
 //删除附件
 func OssDelObject(objectName, ossBucketName string) (bool, error) {
-	common.Catch()
+	defer common.Catch()
 	// 获取存储信息
 	bucket, err := Ossclient.Bucket(ossBucketName)
 	if err != nil {
@@ -67,7 +67,7 @@ func OssDelObject(objectName, ossBucketName string) (bool, error) {
 	return true, err
 }
 func GetHashKey(bs []byte) string {
-	common.Catch()
+	defer common.Catch()
 	ha := sha256.New()
 	ha.Write(bs)
 	hbs := ha.Sum(nil)

+ 2 - 1
rpc/fileCenter.proto

@@ -26,7 +26,8 @@ message UploadResp{
 
 
 message DeleteFileReq{
-	
+	string name=1;
+	string ossBucketName = 2;
 }
 
 service fileCenter {

+ 22 - 0
rpc/filecenter.go

@@ -9,7 +9,9 @@ import (
 	"bp.jydev.jianyu360.cn/BaseService/fileCenter/rpc/internal/svc"
 	"bp.jydev.jianyu360.cn/BaseService/fileCenter/rpc/pb"
 
+	"bp.jydev.jianyu360.cn/BaseService/fileCenter/entity"
 	"github.com/zeromicro/go-zero/core/conf"
+	"github.com/zeromicro/go-zero/core/logx"
 	"github.com/zeromicro/go-zero/core/service"
 	"github.com/zeromicro/go-zero/zrpc"
 	"google.golang.org/grpc"
@@ -18,12 +20,32 @@ import (
 
 var configFile = flag.String("f", "etc/filecenter.yaml", "the config file")
 
+//
+var logFile = flag.String("lf", "etc/log.yaml", "the config file")
+
 func main() {
 	flag.Parse()
 
 	var c config.Config
 	conf.MustLoad(*configFile, &config.C)
 	c = config.C
+
+	//初始化日志信息
+	conf.MustLoad(*logFile, &config.LogC)
+	if len(config.LogC.Level) > 0 {
+		for _, v := range config.LogC.Level {
+			logx.MustSetup(logx.LogConf{
+				Mode:     config.LogC.Mode,
+				Path:     config.LogC.Path,
+				Level:    v,
+				KeepDays: config.LogC.KeepDays,
+			})
+			logx.Info(v, "--日志记录")
+		}
+	}
+	//oss初始化
+	entity.OssInit(c.Oss.OssEndpoint, c.Oss.OssAccessKeyID, c.Oss.OssAccessKeySecret)
+
 	ctx := svc.NewServiceContext(c)
 	svr := server.NewFileCenterServer(ctx)
 

+ 10 - 0
rpc/internal/config/config.go

@@ -14,4 +14,14 @@ type OssStruct struct {
 	OssAccessKeySecret string `json:"ossAccessKeySecret"`
 }
 
+//日志信息
+type Logc struct {
+	Mode     string
+	Path     string
+	Level    []string
+	KeepDays int
+}
+
 var C Config
+
+var LogC Logc

+ 11 - 2
rpc/internal/logic/deletelogic.go

@@ -3,9 +3,10 @@ package logic
 import (
 	"context"
 
+	"app.yhyue.com/moapp/jybase/common"
+	"bp.jydev.jianyu360.cn/BaseService/fileCenter/entity"
 	"bp.jydev.jianyu360.cn/BaseService/fileCenter/rpc/internal/svc"
 	"bp.jydev.jianyu360.cn/BaseService/fileCenter/rpc/pb"
-
 	"github.com/zeromicro/go-zero/core/logx"
 )
 
@@ -26,6 +27,14 @@ func NewDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteLogi
 // 文件删除
 func (l *DeleteLogic) Delete(in *pb.DeleteFileReq) (*pb.FileResp, error) {
 	// todo: add your logic here and delete this line
+	resp := &pb.FileResp{
+		Status: 0,
+	}
+	b, err := entity.OssDelObject(in.Name, common.InterfaceToStr(in.OssBucketName))
+
+	if err == nil && b {
+		resp.Status = 1
+	}
+	return resp, nil
 
-	return &pb.FileResp{}, nil
 }

+ 29 - 8
rpc/pb/fileCenter.pb.go

@@ -231,6 +231,9 @@ type DeleteFileReq struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
+
+	Name          string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
+	OssBucketName string `protobuf:"bytes,2,opt,name=ossBucketName,proto3" json:"ossBucketName,omitempty"`
 }
 
 func (x *DeleteFileReq) Reset() {
@@ -265,6 +268,20 @@ func (*DeleteFileReq) Descriptor() ([]byte, []int) {
 	return file_fileCenter_proto_rawDescGZIP(), []int{3}
 }
 
+func (x *DeleteFileReq) GetName() string {
+	if x != nil {
+		return x.Name
+	}
+	return ""
+}
+
+func (x *DeleteFileReq) GetOssBucketName() string {
+	if x != nil {
+		return x.OssBucketName
+	}
+	return ""
+}
+
 var File_fileCenter_proto protoreflect.FileDescriptor
 
 var file_fileCenter_proto_rawDesc = []byte{
@@ -289,14 +306,18 @@ var file_fileCenter_proto_rawDesc = []byte{
 	0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12,
 	0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72,
 	0x6c, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03,
-	0x6b, 0x65, 0x79, 0x22, 0x0f, 0x0a, 0x0d, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x46, 0x69, 0x6c,
-	0x65, 0x52, 0x65, 0x71, 0x32, 0x54, 0x0a, 0x0a, 0x66, 0x69, 0x6c, 0x65, 0x43, 0x65, 0x6e, 0x74,
-	0x65, 0x72, 0x12, 0x21, 0x0a, 0x06, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x0a, 0x2e, 0x55,
-	0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x71, 0x1a, 0x0b, 0x2e, 0x55, 0x70, 0x6c, 0x6f, 0x61,
-	0x64, 0x52, 0x65, 0x73, 0x70, 0x12, 0x23, 0x0a, 0x06, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12,
-	0x0e, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x1a,
-	0x09, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f,
-	0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+	0x6b, 0x65, 0x79, 0x22, 0x49, 0x0a, 0x0d, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x46, 0x69, 0x6c,
+	0x65, 0x52, 0x65, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01,
+	0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x6f, 0x73, 0x73, 0x42,
+	0x75, 0x63, 0x6b, 0x65, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
+	0x0d, 0x6f, 0x73, 0x73, 0x42, 0x75, 0x63, 0x6b, 0x65, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x32, 0x54,
+	0x0a, 0x0a, 0x66, 0x69, 0x6c, 0x65, 0x43, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x12, 0x21, 0x0a, 0x06,
+	0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x0a, 0x2e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52,
+	0x65, 0x71, 0x1a, 0x0b, 0x2e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x12,
+	0x23, 0x0a, 0x06, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x0e, 0x2e, 0x44, 0x65, 0x6c, 0x65,
+	0x74, 0x65, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x1a, 0x09, 0x2e, 0x46, 0x69, 0x6c, 0x65,
+	0x52, 0x65, 0x73, 0x70, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72,
+	0x6f, 0x74, 0x6f, 0x33,
 }
 
 var (