瀏覽代碼

初始化

xuzhiheng 4 年之前
父節點
當前提交
f92045e9f7
共有 44 個文件被更改,包括 2001 次插入337 次删除
  1. 二進制
      .DS_Store
  2. 二進制
      api/.DS_Store
  3. 41 4
      api/filesystem.api
  4. 二進制
      api/internal/handler/.DS_Store
  5. 29 0
      api/internal/handler/deletefilehandler.go
  6. 29 0
      api/internal/handler/getfilehandler.go
  7. 29 0
      api/internal/handler/getfilemetahandler.go
  8. 25 0
      api/internal/handler/routes.go
  9. 29 0
      api/internal/handler/updatefilemetahandler.go
  10. 29 0
      api/internal/handler/uploadfilehandler.go
  11. 二進制
      api/internal/logic/.DS_Store
  12. 1 1
      api/internal/logic/createdomainlogic.go
  13. 38 0
      api/internal/logic/deletefilelogic.go
  14. 38 0
      api/internal/logic/getfilelogic.go
  15. 37 0
      api/internal/logic/getfilemetalogic.go
  16. 39 0
      api/internal/logic/updatefilemetalogic.go
  17. 61 0
      api/internal/logic/uploadfilelogic.go
  18. 28 0
      api/internal/types/types.go
  19. 3 0
      go.mod
  20. 5 0
      go.sum
  21. 二進制
      rpc/.DS_Store
  22. 10 7
      rpc/etc/filesystem.yaml
  23. 3 2
      rpc/filesystem.proto
  24. 609 306
      rpc/filesystem/filesystem.pb.go
  25. 2 2
      rpc/filesystemclient/filesystem.go
  26. 二進制
      rpc/internal/.DS_Store
  27. 2 0
      rpc/internal/config/config.go
  28. 5 3
      rpc/internal/logic/createdomainlogic.go
  29. 12 1
      rpc/internal/logic/deletefilelogic.go
  30. 23 2
      rpc/internal/logic/getfilelogic.go
  31. 13 2
      rpc/internal/logic/getfilemetalogic.go
  32. 25 3
      rpc/internal/logic/savefilelogic.go
  33. 0 1
      rpc/internal/logic/updatedomainmetalogic.go
  34. 28 2
      rpc/internal/logic/updatefilemetalogic.go
  35. 70 0
      rpc/internal/redis/redisloginutil.go
  36. 518 0
      rpc/internal/redis/redisutil.go
  37. 86 0
      rpc/internal/redis/redisutil_test.go
  38. 二進制
      rpc/internal/svc/.DS_Store
  39. 4 1
      rpc/internal/svc/servicecontext.go
  40. 二進制
      rpc/test/.DS_Store
  41. 14 0
      rpc/test/filesystem.yaml
  42. 91 0
      rpc/test/jyfs_rpc_test.go
  43. 二進制
      test/.DS_Store
  44. 25 0
      test/createdomain_test.go

二進制
.DS_Store


二進制
api/.DS_Store


+ 41 - 4
api/filesystem.api

@@ -6,14 +6,36 @@ info(
 )
 type (
 	CreateDomainReq {
-		name string `form:"name"`
-		meta string `form:"meta"`
+		Name string `form:"name"`
+		Meta string `form:"meta"`
 	}
 	DomainOpResp {
-		state string `json:"state"`
+		State string `json:"state"`
 	}
 	LoadDomainReq {
-		name string `form:"name"`
+		Name string `form:"name"`
+	}
+	LoadFileReq {
+		Domain string `form:"domain"`
+		FileId string `form:"fileId"`
+	}
+	LoadFileOpResp {
+		Meta map[string]string `form:"meta"`
+	}
+	SaveFileReq {
+		Domain string `form:"domain"`
+		FileId string `form:"fileId"`
+	}
+	SaveFileOpResp {
+		State string `json:"state"`
+	}
+	UploadFileReq {
+		Domain string            `form:"domain"`
+		FileId string            `form:"fileId"`
+		Meta   map[string]string `form:"meta"`
+	}
+	UploadFileOpResp {
+		State string `json:"state"`
 	}
 )
 
@@ -24,4 +46,19 @@ service filesystem-api {
 	//删除域
 	@handler DeleteDomain
 	post /filesystem/domain/delete (LoadDomainReq) returns (DomainOpResp)
+	//获取文件元信息
+	@handler GetFileMeta
+	post /filesystem/file/getMeta (LoadFileReq) returns (LoadFileOpResp)
+	//更新文件元信息
+	@handler UpdateFileMeta
+	post /filesystem/file/updateMeta (UploadFileReq) returns (UploadFileOpResp)
+	//上传文件
+	@handler UploadFile
+	post /filesystem/file/upload (UploadFileReq) returns (UploadFileOpResp)
+	//删除文件
+	@handler DeleteFile
+	post /filesystem/file/delete (SaveFileReq) returns (SaveFileOpResp)
+	//获取文件
+	@handler GetFile
+	post /filesystem/file/get (SaveFileReq) returns (SaveFileOpResp)
 }

二進制
api/internal/handler/.DS_Store


+ 29 - 0
api/internal/handler/deletefilehandler.go

@@ -0,0 +1,29 @@
+package handler
+
+import (
+	"net/http"
+
+	"app.yhyue.com/moapp/jyfs/api/internal/logic"
+	"app.yhyue.com/moapp/jyfs/api/internal/svc"
+	"app.yhyue.com/moapp/jyfs/api/internal/types"
+
+	"github.com/tal-tech/go-zero/rest/httpx"
+)
+
+func DeleteFileHandler(ctx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.SaveFileReq
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewDeleteFileLogic(r.Context(), ctx)
+		resp, err := l.DeleteFile(req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 29 - 0
api/internal/handler/getfilehandler.go

@@ -0,0 +1,29 @@
+package handler
+
+import (
+	"net/http"
+
+	"app.yhyue.com/moapp/jyfs/api/internal/logic"
+	"app.yhyue.com/moapp/jyfs/api/internal/svc"
+	"app.yhyue.com/moapp/jyfs/api/internal/types"
+
+	"github.com/tal-tech/go-zero/rest/httpx"
+)
+
+func GetFileHandler(ctx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.SaveFileReq
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewGetFileLogic(r.Context(), ctx)
+		resp, err := l.GetFile(req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 29 - 0
api/internal/handler/getfilemetahandler.go

@@ -0,0 +1,29 @@
+package handler
+
+import (
+	"net/http"
+
+	"app.yhyue.com/moapp/jyfs/api/internal/logic"
+	"app.yhyue.com/moapp/jyfs/api/internal/svc"
+	"app.yhyue.com/moapp/jyfs/api/internal/types"
+
+	"github.com/tal-tech/go-zero/rest/httpx"
+)
+
+func GetFileMetaHandler(ctx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.LoadFileReq
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewGetFileMetaLogic(r.Context(), ctx)
+		resp, err := l.GetFileMeta(req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 25 - 0
api/internal/handler/routes.go

@@ -22,6 +22,31 @@ func RegisterHandlers(engine *rest.Server, serverCtx *svc.ServiceContext) {
 				Path:    "/filesystem/domain/delete",
 				Handler: DeleteDomainHandler(serverCtx),
 			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/filesystem/file/getMeta",
+				Handler: GetFileMetaHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/filesystem/file/updateMeta",
+				Handler: UpdateFileMetaHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/filesystem/file/upload",
+				Handler: UploadFileHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/filesystem/file/delete",
+				Handler: DeleteFileHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/filesystem/file/get",
+				Handler: GetFileHandler(serverCtx),
+			},
 		},
 	)
 }

+ 29 - 0
api/internal/handler/updatefilemetahandler.go

@@ -0,0 +1,29 @@
+package handler
+
+import (
+	"net/http"
+
+	"app.yhyue.com/moapp/jyfs/api/internal/logic"
+	"app.yhyue.com/moapp/jyfs/api/internal/svc"
+	"app.yhyue.com/moapp/jyfs/api/internal/types"
+
+	"github.com/tal-tech/go-zero/rest/httpx"
+)
+
+func UpdateFileMetaHandler(ctx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.UploadFileReq
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewUpdateFileMetaLogic(r.Context(), ctx)
+		resp, err := l.UpdateFileMeta(req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 29 - 0
api/internal/handler/uploadfilehandler.go

@@ -0,0 +1,29 @@
+package handler
+
+import (
+	"net/http"
+
+	"app.yhyue.com/moapp/jyfs/api/internal/logic"
+	"app.yhyue.com/moapp/jyfs/api/internal/svc"
+	"app.yhyue.com/moapp/jyfs/api/internal/types"
+
+	"github.com/tal-tech/go-zero/rest/httpx"
+)
+
+func UploadFileHandler(ctx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.UploadFileReq
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewUploadFileLogic(r.Context(), ctx)
+		resp, err := l.UploadFile(req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

二進制
api/internal/logic/.DS_Store


+ 1 - 1
api/internal/logic/createdomainlogic.go

@@ -32,7 +32,7 @@ func (l *CreateDomainLogic) CreateDomain(req types.CreateDomainReq) (*types.Doma
 		MetaFields: strings.Split(req.Meta, ","),
 	})
 	if err != nil || (resp != nil && !resp.State) {
-		return &types.DomainOpResp{State: "创建失败"}, nil
+		return &types.DomainOpResp{State: "创建失败"}, err
 	} else {
 		return &types.DomainOpResp{State: "创建成功"}, nil
 	}

+ 38 - 0
api/internal/logic/deletefilelogic.go

@@ -0,0 +1,38 @@
+package logic
+
+import (
+	"context"
+
+	"app.yhyue.com/moapp/jyfs/api/internal/svc"
+	"app.yhyue.com/moapp/jyfs/api/internal/types"
+	fsc "app.yhyue.com/moapp/jyfs/rpc/filesystemclient"
+	"github.com/tal-tech/go-zero/core/logx"
+)
+
+type DeleteFileLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewDeleteFileLogic(ctx context.Context, svcCtx *svc.ServiceContext) DeleteFileLogic {
+	return DeleteFileLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *DeleteFileLogic) DeleteFile(req types.SaveFileReq) (*types.SaveFileOpResp, error) {
+	// todo: add your logic here and delete this line
+	resp, err := l.svcCtx.FileSystem.DeleteFile(l.ctx, &fsc.LoadFileReq{
+		Domain: req.Domain,
+		FileId: req.FileId,
+	})
+	if err != nil || resp == nil {
+		return &types.SaveFileOpResp{}, err
+	} else {
+		return &types.SaveFileOpResp{}, nil
+	}
+	return &types.SaveFileOpResp{}, nil
+}

+ 38 - 0
api/internal/logic/getfilelogic.go

@@ -0,0 +1,38 @@
+package logic
+
+import (
+	"context"
+
+	"app.yhyue.com/moapp/jyfs/api/internal/svc"
+	"app.yhyue.com/moapp/jyfs/api/internal/types"
+	fsc "app.yhyue.com/moapp/jyfs/rpc/filesystemclient"
+	"github.com/tal-tech/go-zero/core/logx"
+)
+
+type GetFileLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewGetFileLogic(ctx context.Context, svcCtx *svc.ServiceContext) GetFileLogic {
+	return GetFileLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *GetFileLogic) GetFile(req types.SaveFileReq) (*types.SaveFileOpResp, error) {
+	// todo: add your logic here and delete this line
+	resp, err := l.svcCtx.FileSystem.GetFile(l.ctx, &fsc.LoadFileReq{
+		Domain: req.Domain,
+		FileId: req.FileId,
+	})
+	if err != nil || resp == nil {
+		return &types.SaveFileOpResp{}, err
+	} else {
+		return &types.SaveFileOpResp{}, nil
+	}
+	return &types.SaveFileOpResp{}, nil
+}

+ 37 - 0
api/internal/logic/getfilemetalogic.go

@@ -0,0 +1,37 @@
+package logic
+
+import (
+	"context"
+
+	"app.yhyue.com/moapp/jyfs/api/internal/svc"
+	"app.yhyue.com/moapp/jyfs/api/internal/types"
+	fsc "app.yhyue.com/moapp/jyfs/rpc/filesystemclient"
+	"github.com/tal-tech/go-zero/core/logx"
+)
+
+type GetFileMetaLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewGetFileMetaLogic(ctx context.Context, svcCtx *svc.ServiceContext) GetFileMetaLogic {
+	return GetFileMetaLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *GetFileMetaLogic) GetFileMeta(req types.LoadFileReq) (*types.LoadFileOpResp, error) {
+	// todo: add your logic here and delete this line
+	resp, err := l.svcCtx.FileSystem.GetFileMeta(l.ctx, &fsc.LoadFileReq{
+		Domain: req.Domain,
+		FileId: req.FileId,
+	})
+	if err != nil || resp == nil {
+		return &types.LoadFileOpResp{}, err
+	} else {
+		return &types.LoadFileOpResp{}, nil
+	}
+}

+ 39 - 0
api/internal/logic/updatefilemetalogic.go

@@ -0,0 +1,39 @@
+package logic
+
+import (
+	"context"
+
+	"app.yhyue.com/moapp/jyfs/api/internal/svc"
+	"app.yhyue.com/moapp/jyfs/api/internal/types"
+	fsc "app.yhyue.com/moapp/jyfs/rpc/filesystemclient"
+	"github.com/tal-tech/go-zero/core/logx"
+)
+
+type UpdateFileMetaLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewUpdateFileMetaLogic(ctx context.Context, svcCtx *svc.ServiceContext) UpdateFileMetaLogic {
+	return UpdateFileMetaLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *UpdateFileMetaLogic) UpdateFileMeta(req types.UploadFileReq) (*types.UploadFileOpResp, error) {
+	// todo: add your logic here and delete this line
+	resp, err := l.svcCtx.FileSystem.UpdateFileMeta(l.ctx, &fsc.UpdateFileMetaReq{
+		Domain: req.Domain,
+		FileId: req.FileId,
+		Meta:   req.Meta,
+	})
+	if err != nil || resp == nil {
+		return &types.UploadFileOpResp{}, err
+	} else {
+		return &types.UploadFileOpResp{}, nil
+	}
+	return &types.UploadFileOpResp{}, nil
+}

+ 61 - 0
api/internal/logic/uploadfilelogic.go

@@ -0,0 +1,61 @@
+package logic
+
+import (
+	"context"
+	"fmt"
+	"os"
+
+	"app.yhyue.com/moapp/jyfs/api/internal/svc"
+	"app.yhyue.com/moapp/jyfs/api/internal/types"
+	fsc "app.yhyue.com/moapp/jyfs/rpc/filesystemclient"
+	"github.com/tal-tech/go-zero/core/logx"
+)
+
+type UploadFileLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewUploadFileLogic(ctx context.Context, svcCtx *svc.ServiceContext) UploadFileLogic {
+	return UploadFileLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *UploadFileLogic) UploadFile(req types.UploadFileReq) (*types.UploadFileOpResp, error) {
+	// todo: add your logic here and delete this line
+	file, err := os.Open("./que.txt")
+	if err != nil {
+		return nil, err
+	}
+	defer file.Close()
+
+	// FileInfo:
+	stats, err := file.Stat()
+	if err != nil {
+		return nil, err
+	}
+
+	// []byte
+	data := make([]byte, stats.Size())
+	count, err := file.Read(data)
+	if err != nil {
+		return nil, err
+	}
+	fmt.Println(count)
+	resp, err := l.svcCtx.FileSystem.SaveFile(l.ctx, &fsc.SaveFileReq{
+		Domain:         req.Domain,
+		FileId:         req.FileId,
+		Meta:           req.Meta,
+		RawFileContent: data,
+	})
+	if err != nil || resp == nil {
+		return &types.UploadFileOpResp{}, err
+	} else {
+		return &types.UploadFileOpResp{}, nil
+	}
+	return &types.UploadFileOpResp{}, nil
+}

+ 28 - 0
api/internal/types/types.go

@@ -13,3 +13,31 @@ type DomainOpResp struct {
 type LoadDomainReq struct {
 	Name string `form:"name"`
 }
+
+type LoadFileReq struct {
+	Domain string `form:"domain"`
+	FileId string `form:"fileId"`
+}
+
+type LoadFileOpResp struct {
+	Meta map[string]string `form:"meta"`
+}
+
+type SaveFileReq struct {
+	Domain string `form:"domain"`
+	FileId string `form:"fileId"`
+}
+
+type SaveFileOpResp struct {
+	State string `json:"state"`
+}
+
+type UploadFileReq struct {
+	Domain string            `form:"domain"`
+	FileId string            `form:"fileId"`
+	Meta   map[string]string `form:"meta"`
+}
+
+type UploadFileOpResp struct {
+	State string `json:"state"`
+}

+ 3 - 0
go.mod

@@ -5,10 +5,13 @@ go 1.14
 require (
 	github.com/aliyun/aliyun-oss-go-sdk v2.1.6+incompatible
 	github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect
+	github.com/garyburd/redigo v1.6.2
 	github.com/golang/protobuf v1.4.2
+	github.com/gomodule/redigo v1.8.4
 	github.com/satori/go.uuid v1.2.0 // indirect
 	github.com/tal-tech/go-zero v1.1.2
 	google.golang.org/grpc v1.29.1
+	google.golang.org/protobuf v1.25.0
 )
 
 replace google.golang.org/grpc => google.golang.org/grpc v1.29.1

+ 5 - 0
go.sum

@@ -56,6 +56,8 @@ github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4
 github.com/frankban/quicktest v1.7.2/go.mod h1:jaStnuzAqU1AJdCO0l53JDCJrVDKcS03DbaAcR7Ks/o=
 github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
 github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
+github.com/garyburd/redigo v1.6.2 h1:yE/pwKCrbLpLpQICzYTeZ7JsTA/C53wFTJHaEtRqniM=
+github.com/garyburd/redigo v1.6.2/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY=
 github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
 github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
 github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
@@ -95,6 +97,9 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq
 github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
 github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
 github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
+github.com/gomodule/redigo v1.8.4 h1:Z5JUg94HMTR1XpwBaSH4vq3+PNSIykBLxMdglbw10gg=
+github.com/gomodule/redigo v1.8.4/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0=
+github.com/gomodule/redigo/redis v0.0.0-do-not-use h1:J7XIp6Kau0WoyT4JtXHT3Ei0gA1KkSc6bc87j9v9WIo=
 github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo=
 github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
 github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=

二進制
rpc/.DS_Store


+ 10 - 7
rpc/etc/filesystem.yaml

@@ -1,11 +1,14 @@
 Name: filesystem.rpc
-ListenOn: 192.168.20.106:8080
+ListenOn: 192.168.20.36:8080
 #阿里云OSS配置
 OssEndPoint: "oss-cn-beijing.aliyuncs.com"
-OssAccessKeyId: ""
-OssAccessKeySecret: ""
+OssAccessKeyId: "LTAI4G4HRNnS7qeHwMRkzJ9k"
+OssAccessKeySecret: "rlUFOkaK4fAfLWxvKBORSwWhf75bQx"
 #etcd配置
-Etcd:
-  Hosts:
-    - 192.168.3.240:2379
-  Key: moapp.filesystem.rpc
+FileSystemConf:
+  Etcd:
+    Hosts:
+      - 192.168.3.240:2379
+    Key: moapp.filesystem.rpc
+#redis
+RedisAddress: "jyfs=192.168.3.128:5002"

+ 3 - 2
rpc/filesystem.proto

@@ -13,8 +13,9 @@ message DomainResp {
 //
 message SaveFileReq {
   string domain = 1;//存入哪个buckets
-  map<string, string> meta = 2;//元数据
-  bytes rawFileContent = 3;//文件内容
+  string fileId = 2;
+  map<string, string> meta = 3;//元数据
+  bytes rawFileContent = 4;//文件内容
 }
 //
 message FileOpResp {

文件差異過大導致無法顯示
+ 609 - 306
rpc/filesystem/filesystem.pb.go


+ 2 - 2
rpc/filesystemclient/filesystem.go

@@ -14,14 +14,14 @@ import (
 )
 
 type (
-	FileOpResp        = filesystem.FileOpResp
-	UpdateFileMetaReq = filesystem.UpdateFileMetaReq
 	LoadFileReq       = filesystem.LoadFileReq
 	LoadFileResp      = filesystem.LoadFileResp
 	LoadFileMetaResp  = filesystem.LoadFileMetaResp
 	DomainReq         = filesystem.DomainReq
 	DomainResp        = filesystem.DomainResp
 	SaveFileReq       = filesystem.SaveFileReq
+	FileOpResp        = filesystem.FileOpResp
+	UpdateFileMetaReq = filesystem.UpdateFileMetaReq
 
 	FileSystem interface {
 		// 创建域

二進制
rpc/internal/.DS_Store


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

@@ -7,4 +7,6 @@ type Config struct {
 	OssEndPoint        string
 	OssAccessKeyId     string
 	OssAccessKeySecret string
+	FileSystemConf     zrpc.RpcClientConf
+	RedisAddress       string
 }

+ 5 - 3
rpc/internal/logic/createdomainlogic.go

@@ -1,10 +1,11 @@
 package logic
 
 import (
-	"app.yhyue.com/moapp/jyfs/rpc/filesystem"
-	"app.yhyue.com/moapp/jyfs/rpc/internal/svc"
 	"context"
 
+	"app.yhyue.com/moapp/jyfs/rpc/filesystem"
+	"app.yhyue.com/moapp/jyfs/rpc/internal/redis"
+	"app.yhyue.com/moapp/jyfs/rpc/internal/svc"
 	"github.com/tal-tech/go-zero/core/logx"
 )
 
@@ -27,8 +28,9 @@ func (l *CreateDomainLogic) CreateDomain(in *filesystem.DomainReq) (*filesystem.
 	err := l.svcCtx.OssClient.CreateBucket(in.Name)
 	// todo: 本地存储bucket和meta的对应关系
 	if err != nil {
-		return &filesystem.DomainResp{State: false}, nil
+		return &filesystem.DomainResp{State: false}, err
 	} else {
+		redis.Put("jyfs", in.Name, 1, -1)
 		return &filesystem.DomainResp{State: true}, nil
 	}
 }

+ 12 - 1
rpc/internal/logic/deletefilelogic.go

@@ -26,6 +26,17 @@ func NewDeleteFileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Delete
 // 删除文件
 func (l *DeleteFileLogic) DeleteFile(in *filesystem.LoadFileReq) (*filesystem.FileOpResp, error) {
 	// todo: add your logic here and delete this line
+	// 获取存储空间。
+	bucket, err := l.svcCtx.OssClient.Bucket(in.Domain)
+	if err != nil {
+		return &filesystem.FileOpResp{}, nil
+	}
 
-	return &filesystem.FileOpResp{}, nil
+	// 删除单个文件。objectName表示删除OSS文件时需要指定包含文件后缀在内的完整路径
+	// 如需删除文件夹,请将objectName设置为对应的文件夹名称。如果文件夹非空,则需要将文件夹下的所有object删除后才能删除该文件夹。
+	err = bucket.DeleteObject(in.FileId)
+	if err != nil {
+		return &filesystem.FileOpResp{State: false}, nil
+	}
+	return &filesystem.FileOpResp{State: true}, nil
 }

+ 23 - 2
rpc/internal/logic/getfilelogic.go

@@ -3,9 +3,11 @@ package logic
 import (
 	"context"
 
+	"fmt"
+	"io/ioutil"
+
 	"app.yhyue.com/moapp/jyfs/rpc/filesystem"
 	"app.yhyue.com/moapp/jyfs/rpc/internal/svc"
-
 	"github.com/tal-tech/go-zero/core/logx"
 )
 
@@ -26,6 +28,25 @@ func NewGetFileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFileLo
 // 获取文件
 func (l *GetFileLogic) GetFile(in *filesystem.LoadFileReq) (*filesystem.LoadFileResp, error) {
 	// todo: add your logic here and delete this line
+	// 获取存储空间。
+	bucket, err := l.svcCtx.OssClient.Bucket(in.Domain)
+	if err != nil {
+		return &filesystem.LoadFileResp{}, err
+	}
+	fmt.Println("data:", in.Domain)
+	fmt.Println("data:", in.FileId)
+	// 下载文件到流。
+	body, err := bucket.GetObject(in.FileId)
+	if err != nil {
+		return &filesystem.LoadFileResp{}, err
+	}
+	// 数据读取完成后,获取的流必须关闭,否则会造成连接泄漏,导致请求无连接可用,程序无法正常工作。
+	defer body.Close()
 
-	return &filesystem.LoadFileResp{}, nil
+	data, err := ioutil.ReadAll(body)
+	if err != nil {
+		return &filesystem.LoadFileResp{}, err
+	}
+	fmt.Println("data:", string(data))
+	return &filesystem.LoadFileResp{RawFileContent: data}, nil
 }

+ 13 - 2
rpc/internal/logic/getfilemetalogic.go

@@ -3,9 +3,10 @@ package logic
 import (
 	"context"
 
+	"fmt"
+
 	"app.yhyue.com/moapp/jyfs/rpc/filesystem"
 	"app.yhyue.com/moapp/jyfs/rpc/internal/svc"
-
 	"github.com/tal-tech/go-zero/core/logx"
 )
 
@@ -26,6 +27,16 @@ func NewGetFileMetaLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFi
 // 获取文件元数据
 func (l *GetFileMetaLogic) GetFileMeta(in *filesystem.LoadFileReq) (*filesystem.LoadFileMetaResp, error) {
 	// todo: add your logic here and delete this line
-
+	// // 获取存储空间。
+	bucket, err := l.svcCtx.OssClient.Bucket(in.Domain)
+	if err != nil {
+		return &filesystem.LoadFileMetaResp{}, nil
+	}
+	// 获取文件元信息。
+	props, err := bucket.GetObjectDetailedMeta(in.FileId)
+	if err != nil {
+		return &filesystem.LoadFileMetaResp{}, nil
+	}
+	fmt.Println("Object Meta:", props)
 	return &filesystem.LoadFileMetaResp{}, nil
 }

+ 25 - 3
rpc/internal/logic/savefilelogic.go

@@ -6,6 +6,10 @@ import (
 	"app.yhyue.com/moapp/jyfs/rpc/filesystem"
 	"app.yhyue.com/moapp/jyfs/rpc/internal/svc"
 
+	"bytes"
+
+	// "app.yhyue.com/moapp/jyfs/rpc/internal/redis"
+	"github.com/aliyun/aliyun-oss-go-sdk/oss"
 	"github.com/tal-tech/go-zero/core/logx"
 )
 
@@ -25,7 +29,25 @@ func NewSaveFileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveFile
 
 // 保存文件
 func (l *SaveFileLogic) SaveFile(in *filesystem.SaveFileReq) (*filesystem.FileOpResp, error) {
-	// todo: add your logic here and delete this line
-
-	return &filesystem.FileOpResp{}, nil
+	// 获取存储空间。
+	bucket, err := l.svcCtx.OssClient.Bucket(in.Domain)
+	if err != nil {
+		return &filesystem.FileOpResp{State: false}, err
+	}
+	// 设置文件元信息:过期时间为2049年1月10日 23:00:00 GMT,访问权限为公共读,自定义元信息为MyProp(取值MyPropVal)。
+	// expires := time.Date(2049, time.January, 10, 23, 0, 0, 0, time.UTC)
+	options := []oss.Option{
+		// oss.Expires(expires),
+		// oss.ObjectACL(oss.ACLPublicRead),
+		// oss.Meta("MyProp", "MyPropVal"),
+	}
+	for k, v := range in.Meta {
+		options = append(options, oss.Meta(k, v))
+	}
+	// 上传Byte数组。
+	err = bucket.PutObject(in.FileId, bytes.NewReader(in.RawFileContent), options...)
+	if err != nil {
+		return &filesystem.FileOpResp{}, err
+	}
+	return &filesystem.FileOpResp{State: true, FileId: in.FileId}, nil
 }

+ 0 - 1
rpc/internal/logic/updatedomainmetalogic.go

@@ -26,6 +26,5 @@ func NewUpdateDomainMetaLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
 // 更新域
 func (l *UpdateDomainMetaLogic) UpdateDomainMeta(in *filesystem.DomainReq) (*filesystem.DomainResp, error) {
 	// todo: add your logic here and delete this line
-
 	return &filesystem.DomainResp{}, nil
 }

+ 28 - 2
rpc/internal/logic/updatefilemetalogic.go

@@ -3,9 +3,11 @@ package logic
 import (
 	"context"
 
+	"fmt"
+
 	"app.yhyue.com/moapp/jyfs/rpc/filesystem"
 	"app.yhyue.com/moapp/jyfs/rpc/internal/svc"
-
+	"github.com/aliyun/aliyun-oss-go-sdk/oss"
 	"github.com/tal-tech/go-zero/core/logx"
 )
 
@@ -26,6 +28,30 @@ func NewUpdateFileMetaLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Up
 // 更新文件元数据
 func (l *UpdateFileMetaLogic) UpdateFileMeta(in *filesystem.UpdateFileMetaReq) (*filesystem.FileOpResp, error) {
 	// todo: add your logic here and delete this line
+	// 获取存储空间。
+	bucket, err := l.svcCtx.OssClient.Bucket(in.Domain)
+	if err != nil {
+		return &filesystem.FileOpResp{}, err
+	}
+
+	// 一次修改多条元信息。
+	options := []oss.Option{
+		// oss.Meta("MyMeta", "MyMetaValue2"),
+		// oss.Meta("MyObjectLocation", "HangZhou"),
+	}
+	for k, v := range in.Meta {
+		options = append(options, oss.Meta(k, v))
+	}
+	err = bucket.SetObjectMeta(in.FileId, options...)
+	if err != nil {
+		return &filesystem.FileOpResp{State: false}, err
+	}
 
-	return &filesystem.FileOpResp{}, nil
+	// 获取文件元信息。
+	props, err := bucket.GetObjectDetailedMeta(in.FileId)
+	if err != nil {
+		return &filesystem.FileOpResp{}, err
+	}
+	fmt.Println("Object Meta:", props)
+	return &filesystem.FileOpResp{State: true}, nil
 }

+ 70 - 0
rpc/internal/redis/redisloginutil.go

@@ -0,0 +1,70 @@
+package redis
+
+import (
+	"log"
+	"strings"
+	"time"
+
+	redisLogin "github.com/gomodule/redigo/redis"
+)
+
+var RedisLoginPool *redisLogin.Pool
+
+func InitRedisLogin(addrs string) {
+	addr := strings.Split(addrs, ",")
+	for _, v := range addr {
+		saddr := strings.Split(v, "=")
+		if saddr[0] == "login" {
+			RedisLoginPool = &redisLogin.Pool{MaxActive: 10, MaxIdle: 5,
+				IdleTimeout: time.Duration(10) * time.Second, Dial: func() (redisLogin.Conn, error) {
+					c, err := redisLogin.Dial("tcp", saddr[1])
+					if err != nil {
+						return nil, err
+					}
+					return c, nil
+				}}
+		}
+	}
+
+}
+
+//
+func SetLoginVal(key, value string) {
+	conn := RedisLoginPool.Get()
+	defer conn.Close()
+	conn.Do("PUBLISH", key, value)
+}
+
+//
+func GetLoginVal(key string, wxFunc func(wxParams []string) bool) {
+	for {
+		defer catch()
+	L:
+		for {
+			conn := RedisLoginPool.Get()
+			defer conn.Close()
+			if conn.Err() == nil {
+				psc := redisLogin.PubSubConn{Conn: conn}
+				if err := psc.Subscribe(redisLogin.Args{}.AddFlat(key)...); err != nil {
+					log.Println(err)
+				}
+				for {
+					msg := psc.Receive()
+					//					go func(msg interface{}) {
+					switch n := msg.(type) {
+					case error:
+						log.Println("wxlogin err", msg)
+						break L
+					case redisLogin.Message:
+						res := string(n.Data)
+						param := strings.Split(res, ",")
+						go wxFunc(param)
+					}
+					//					}(msg)
+				}
+			}
+			time.Sleep(2 * time.Second)
+		}
+		time.Sleep(1 * time.Second)
+	}
+}

+ 518 - 0
rpc/internal/redis/redisutil.go

@@ -0,0 +1,518 @@
+package redis
+
+import (
+	"encoding/json"
+	"errors"
+	"log"
+	"runtime"
+	"strings"
+	"time"
+
+	redigo "github.com/garyburd/redigo/redis"
+)
+
+var RedisPool map[string]*redigo.Pool
+
+//初始化redis 1为多个连接池,2为共用一个连接池
+func InitRedis(addrs string) {
+	InitRedisBySize(addrs, 300, 30, 240)
+}
+
+func InitRedisBySize(addrs string, maxSize, maxIdle, timeout int) {
+	RedisPool = map[string]*redigo.Pool{}
+	addr := strings.Split(addrs, ",")
+	for _, v := range addr {
+		saddr := strings.Split(v, "=")
+		RedisPool[saddr[0]] = &redigo.Pool{MaxActive: maxSize, MaxIdle: maxIdle,
+			IdleTimeout: time.Duration(timeout) * time.Second, Dial: func() (redigo.Conn, error) {
+				c, err := redigo.Dial("tcp", saddr[1])
+				if err != nil {
+					return nil, err
+				}
+				return c, nil
+			}}
+	}
+}
+
+//分流redis
+//并存入字符串缓存
+func PutKV(key string, obj interface{}) bool {
+	return Put("other", key, obj, -1)
+}
+func PutCKV(code, key string, obj interface{}) bool {
+	return Put(code, key, obj, -1)
+}
+func Put(code, key string, obj interface{}, timeout int) bool {
+	b := false
+	defer catch()
+	conn := RedisPool[code].Get()
+	defer conn.Close()
+	var err error
+	_obj, _err := json.Marshal(obj)
+	if _err != nil {
+		log.Println("redisutil-SET-序列化出错Error", _err)
+		return b
+	}
+	if timeout < 1 {
+		_, err = conn.Do("SET", key, _obj)
+	} else {
+		_, err = conn.Do("SET", key, _obj, "EX", timeout)
+	}
+	if nil != err {
+		log.Println("redisutil-SETError-put", err)
+	} else {
+		b = true
+	}
+	return b
+}
+
+func BulkPut(code string, timeout int, obj ...interface{}) bool {
+	b := false
+	defer catch()
+	conn := RedisPool[code].Get()
+	defer conn.Close()
+	var err error
+	for _, _tmp := range obj {
+		tmp, ok := _tmp.([]interface{})
+		if ok && len(tmp) == 2 {
+			key, kok := tmp[0].(string)
+			if kok && key != "" {
+				_obj, _err := json.Marshal(tmp[1])
+				if _err != nil {
+					log.Println("redisutil-SET-序列化出错Error", _err)
+					return b
+				}
+				if timeout < 1 {
+					_, err = conn.Do("SET", key, _obj)
+				} else {
+					_, err = conn.Do("SET", key, _obj, "EX", timeout)
+				}
+			}
+		}
+	}
+	if nil != err {
+		b = false
+		log.Println("redisutil-SETError-put", err)
+	} else {
+		b = b && true
+	}
+	return b
+}
+
+//直接存字节流
+func PutBytes(code, key string, data *[]byte, timeout int) (err error) {
+	defer catch()
+
+	conn := RedisPool[code].Get()
+	defer conn.Close()
+
+	if timeout < 1 {
+		_, err = conn.Do("SET", key, *data)
+	} else {
+		_, err = conn.Do("SET", key, *data, "EX", timeout)
+	}
+	if nil != err {
+		log.Println("redisutil-SETError", err)
+	}
+	return
+}
+
+//设置超时时间,单位秒
+func SetExpire(code, key string, expire int) error {
+	defer catch()
+
+	conn := RedisPool[code].Get()
+	defer conn.Close()
+	_, err := conn.Do("expire", key, expire)
+	return err
+}
+
+//判断一个key是否存在
+func Exists(code, key string) (bool, error) {
+	defer catch()
+
+	conn := RedisPool[code].Get()
+	defer conn.Close()
+	repl, err := conn.Do("exists", key)
+	ret, _ := redigo.Int(repl, err)
+	return ret == 1, err
+}
+
+//获取string
+func GetStr(code, key string) string {
+	res := Get(code, key)
+	str, _ := res.(string)
+	return str
+}
+
+//获取int
+func GetInt(code, key string) int {
+	result, _ := GetNewInt(code, key)
+	return result
+}
+
+func GetNewInt(code, key string) (int, error) {
+	var res interface{}
+	err := GetNewInterface(code, key, &res)
+	var result int
+	if str, ok := res.(float64); ok {
+		result = int(str)
+	}
+	return result, err
+}
+
+//取得字符串,支持变参,2个 (key,code),返回后自己断言
+func Get(code, key string) (result interface{}) {
+	GetInterface(code, key, &result)
+	return
+}
+
+func GetInterface(code, key string, result interface{}) {
+	GetNewInterface(code, key, result)
+}
+
+func GetNewInterface(code, key string, result interface{}) error {
+	defer catch()
+	conn := RedisPool[code].Get()
+	defer conn.Close()
+	ret, err := conn.Do("GET", key)
+	if nil != err {
+		log.Println("redisutil-GetError", err)
+	} else {
+		var ok bool
+		var res []byte
+		if res, ok = ret.([]byte); ok {
+			err = json.Unmarshal(res, result)
+			if err != nil {
+				log.Println("Get ERROR:", err.Error())
+			}
+		}
+	}
+	return err
+}
+
+//直接返回字节流
+func GetBytes(code, key string) (ret *[]byte, err error) {
+	defer catch()
+
+	conn := RedisPool[code].Get()
+	defer conn.Close()
+	var r interface{}
+	r, err = conn.Do("GET", key)
+	if err != nil {
+		log.Println("redisutil-GetBytesError", err)
+	} else {
+		if tmp, ok := r.([]byte); ok {
+			ret = &tmp
+		} else {
+			err = errors.New("redis返回数据格式不对")
+		}
+	}
+	return
+}
+func GetNewBytes(code, key string) (ret *[]byte, err error) {
+	defer catch()
+	redisPool := RedisPool[code]
+	if redisPool == nil {
+		err = errors.New("redis code " + code + " is nil")
+		log.Println("redisutil-GetNewBytesError", err)
+		return
+	}
+	conn := redisPool.Get()
+	defer conn.Close()
+	var r interface{}
+	r, err = conn.Do("GET", key)
+	if err != nil {
+		log.Println("redisutil-GetNewBytesError", err)
+	} else if r != nil {
+		if tmp, ok := r.([]byte); ok {
+			ret = &tmp
+		}
+	}
+	return
+}
+
+//删所有key
+func FlushDB(code string) bool {
+	b := false
+	defer catch()
+
+	conn := RedisPool[code].Get()
+	defer conn.Close()
+
+	var err error
+	_, err = conn.Do("FLUSHDB")
+	if nil != err {
+		log.Println("redisutil-FLUSHDBError", err)
+	} else {
+		b = true
+	}
+	return b
+}
+
+//支持删除多个key
+func Del(code string, key ...interface{}) bool {
+	defer catch()
+	b := false
+	conn := RedisPool[code].Get()
+	defer conn.Close()
+
+	var err error
+	_, err = conn.Do("DEL", key...)
+	if nil != err {
+		log.Println("redisutil-DELError", err)
+	} else {
+		b = true
+	}
+	return b
+}
+
+/**
+func DelKey(key ...interface{}) {
+	defer func() {
+		if r := recover(); r != nil {
+			log.Println("[E]", r)
+			for skip := 1; ; skip++ {
+				_, file, line, ok := runtime.Caller(skip)
+				if !ok {
+					break
+				}
+				go log.Printf("%v,%v\n", file, line)
+			}
+		}
+	}()
+	for i := 0; i < len(RedisPool); i++ {
+		delByNum(i, key...)
+	}
+
+}
+**/
+
+/**
+func delByNum(n int, key ...interface{}) {
+	defer func() {
+		if r := recover(); r != nil {
+			log.Println("[E]", r)
+			for skip := 1; ; skip++ {
+				_, file, line, ok := runtime.Caller(skip)
+				if !ok {
+					break
+				}
+				go log.Printf("%v,%v\n", file, line)
+			}
+		}
+	}()
+	i := 0
+	for _, v := range RedisPool {
+		if i == n {
+			conn := v.Get()
+			defer conn.Close()
+			conn.Do("DEL", key...)
+			break
+		}
+		i++
+	}
+}
+**/
+
+//根据代码和前辍key删除多个
+func DelByCodePattern(code, key string) {
+	defer catch()
+
+	conn := RedisPool[code].Get()
+	defer conn.Close()
+	ret, err := conn.Do("KEYS", key)
+	var result []interface{}
+	if nil != err {
+		log.Println("redisutil-GetError", err)
+	} else {
+		result = ret.([]interface{})
+		for k := 0; k < len(result); k++ {
+			conn.Do("DEL", string(result[k].([]uint8)))
+		}
+	}
+}
+
+/**
+func DelByPattern(key string) {
+	defer func() {
+		if r := recover(); r != nil {
+			log.Println("[E]", r)
+			for skip := 1; ; skip++ {
+				_, file, line, ok := runtime.Caller(skip)
+				if !ok {
+					break
+				}
+				go log.Printf("%v,%v\n", file, line)
+			}
+		}
+	}()
+	i := 0
+	for _, v := range RedisPool {
+		conn := v.Get()
+		defer conn.Close()
+		ret, err := conn.Do("KEYS", key)
+		var result []interface{}
+		if nil != err {
+			log.Println("redisutil-GetError", err)
+		} else {
+			result = ret.([]interface{})
+			for k := 0; k < len(result); k++ {
+				delByNum(i, string(result[k].([]uint8)))
+			}
+		}
+		i++
+	}
+
+}
+**/
+//自增计数器
+func Incr(code, key string) int64 {
+	defer catch()
+	conn := RedisPool[code].Get()
+	defer conn.Close()
+	ret, err := conn.Do("INCR", key)
+	if nil != err {
+		log.Println("redisutil-INCR-Error", err)
+	} else {
+		if res, ok := ret.(int64); ok {
+			return res
+		} else {
+			return 0
+		}
+	}
+	return 0
+}
+
+//自减
+func Decrby(code, key string, val int) int64 {
+	defer catch()
+	conn := RedisPool[code].Get()
+	defer conn.Close()
+	ret, err := conn.Do("DECRBY", key, val)
+	if nil != err {
+		log.Println("redisutil-DECR-Error", err)
+	} else {
+		if res, ok := ret.(int64); ok {
+			return res
+		} else {
+			return 0
+		}
+	}
+	return 0
+}
+
+//根据正则去取
+func GetKeysByPattern(code, key string) []interface{} {
+	defer catch()
+	conn := RedisPool[code].Get()
+	defer conn.Close()
+	ret, err := conn.Do("KEYS", key)
+	if nil != err {
+		log.Println("redisutil-GetKeysError", err)
+		return nil
+	} else {
+		res, _ := ret.([]interface{})
+		return res
+	}
+}
+
+//批量取多个key
+func Mget(code string, key []string) []interface{} {
+	defer catch()
+	conn := RedisPool[code].Get()
+	defer conn.Close()
+	interfaceKeys := make([]interface{}, len(key))
+	for n, k := range key {
+		interfaceKeys[n] = k
+	}
+	ret, err := conn.Do("MGET", interfaceKeys...)
+	if nil != err {
+		log.Println("redisutil-MgetError", err)
+		return nil
+	} else {
+		res, _ := ret.([]interface{})
+		return res
+	}
+}
+
+//取出并删除Key
+func Pop(code string, key string) (result interface{}) {
+	defer catch()
+	conn := RedisPool[code].Get()
+	defer conn.Close()
+	ret, err := conn.Do("GET", key)
+	if nil != err {
+		log.Println("redisutil-PopError", err)
+	} else {
+		var ok bool
+		var res []byte
+		if res, ok = ret.([]byte); ok {
+			err = json.Unmarshal(res, &result)
+			if err != nil {
+				log.Println("Poperr", err)
+			}
+		}
+		conn.Do("DEL", key)
+	}
+	return
+}
+
+//list操作
+func LPOP(code, list string) (result interface{}) {
+	defer catch()
+	conn := RedisPool[code].Get()
+	defer conn.Close()
+	ret, err := conn.Do("LPOP", list)
+	if nil != err {
+		log.Println("redisutil-LPopError", err)
+	} else {
+		if res, ok := ret.([]byte); ok {
+			err = json.Unmarshal(res, &result)
+			log.Println(err)
+		}
+	}
+	return
+}
+
+func RPUSH(code, list string, val interface{}) bool {
+	defer catch()
+	conn := RedisPool[code].Get()
+	defer conn.Close()
+	_obj, _ := json.Marshal(val)
+	_, err := conn.Do("RPUSH", list, _obj)
+	if nil != err {
+		log.Println("redisutil-RPUSHError", err)
+		return false
+	}
+	return true
+}
+
+func LLEN(code, list string) int64 {
+	defer catch()
+	conn := RedisPool[code].Get()
+	defer conn.Close()
+	ret, err := conn.Do("LLEN", list)
+	if nil != err {
+		log.Println("redisutil-LLENError", err)
+		return 0
+	}
+	if res, ok := ret.(int64); ok {
+		return res
+	} else {
+		return 0
+	}
+}
+
+func catch() {
+	if r := recover(); r != nil {
+		log.Println(r)
+		for skip := 0; ; skip++ {
+			_, file, line, ok := runtime.Caller(skip)
+			if !ok {
+				break
+			}
+			go log.Printf("%v,%v\n", file, line)
+		}
+	}
+}

+ 86 - 0
rpc/internal/redis/redisutil_test.go

@@ -0,0 +1,86 @@
+package redis
+
+import (
+	"fmt"
+	"log"
+	"testing"
+	"time"
+)
+
+func Test_redis(t *testing.T) {
+	InitRedis("192.168.3.142:6379,192.168.3.142:7379")
+
+	log.Println(PutKV("key-BBB", "v-oooo"))
+	log.Println(GetStr("", "key-BBB"))
+
+	log.Println(PutCKV("code-K", "key-BBB2", 123))
+	log.Println(GetInt("code-K", "key-BBB2"))
+
+	log.Println(Put("codeA", "BBB", "oooo", 0))
+	//log.Println(Del("codeA", "AAA"))
+	log.Println(GetStr("codeA", "AAA"))
+
+	log.Println(Put("code", "Key", &map[string]string{"name": "张三"}, 0))
+	log.Println(Get("code", "Key"))
+}
+
+func Test_redisMorePut(t *testing.T) {
+	//by := []byte("dddddddddddd555d")
+
+	//InitRedis("enterprise=192.168.3.14:1379,service=192.168.3.14:2379,other=192.168.3.14:3379")
+	InitRedis("sso=192.168.3.14:1379")
+	//PutBytes("enterprise", "A", &by, 0)
+	//Put("sso", "new_1070776706", "obEpLuMMDUYUM-zlzCbQ0MbuQOzc", 180)
+	Put("sso", "1903540616", "oJULtwzXo6EFV1Ah-XeyRBimXGM8", 180)
+	//log.Println(Get("enterprise", "A"))
+	//GetMoreKey("ent*")
+}
+
+func Test_other(t *testing.T) {
+	//s := `[{"S_remark":"kokopkopkop","s_pic":"/upload/2015/10/16/2015101611194101018681.jpg","o_extend":{"k1":"ioio","k7":"000"}}]`
+	//mo := []map[string]interface{}{}
+	//json.Unmarshal([]byte(s), &mo)
+	//log.Println(mo)
+
+	pools := make(chan bool, 1)
+	pool := make(chan bool, 2)
+	for i := 0; i < 1000; i++ {
+		go func(i int) {
+			pool <- true
+			defer func() {
+				<-pool
+			}()
+			log.Println("--", i)
+			time.Sleep(5 * time.Millisecond)
+
+		}(i)
+	}
+	<-pools
+}
+
+func TestIncr(t *testing.T) {
+	InitRedis("other=192.168.3.14:1379")
+	//log.Println(GetBytes("sso", "p_share_3200000006"))
+	Put("other", "test", "12212212", 50000)
+}
+
+func Test_Pop(t *testing.T) {
+	InitRedis("sso=192.168.3.207:1601")
+	m := "aaaa"
+	Put("sso", "aaa", m, 1000)
+	log.Println(Pop("sso", "aaa"))
+}
+
+func Test_MGET(t *testing.T) {
+	InitRedis("sso=192.168.3.207:3378")
+	InitRedis("sso=192.168.3.207:1711")
+	n := 0
+	for {
+		n++
+		Put("sso", fmt.Sprintf("%d_1", n), n, 3600)
+		time.Sleep(8 * time.Second)
+
+	}
+	res := Mget("sso", []string{"pn_金业街(西自由街-虎泉路)道路建设工程"})
+	log.Println(res)
+}

二進制
rpc/internal/svc/.DS_Store


+ 4 - 1
rpc/internal/svc/servicecontext.go

@@ -1,9 +1,11 @@
 package svc
 
 import (
+	"log"
+
 	"app.yhyue.com/moapp/jyfs/rpc/internal/config"
+	"app.yhyue.com/moapp/jyfs/rpc/internal/redis"
 	"github.com/aliyun/aliyun-oss-go-sdk/oss"
-	"log"
 )
 
 type ServiceContext struct {
@@ -16,6 +18,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
 	if err != nil {
 		log.Fatal(err)
 	}
+	redis.InitRedisBySize(c.RedisAddress, 100, 30, 300)
 	return &ServiceContext{
 		Config:    c,
 		OssClient: client,

二進制
rpc/test/.DS_Store


+ 14 - 0
rpc/test/filesystem.yaml

@@ -0,0 +1,14 @@
+Name: filesystem.rpc
+ListenOn: 192.168.20.36:8080
+#阿里云OSS配置
+OssEndPoint: "oss-cn-beijing.aliyuncs.com"
+OssAccessKeyId: "LTAI4G4HRNnS7qeHwMRkzJ9k"
+OssAccessKeySecret: "rlUFOkaK4fAfLWxvKBORSwWhf75bQx"
+#etcd配置
+FileSystemConf:
+  Etcd:
+    Hosts:
+      - 192.168.3.240:2379
+    Key: moapp.filesystem.rpc
+#redis
+RedisAddress: "jyfs=192.168.3.128:5002"

+ 91 - 0
rpc/test/jyfs_rpc_test.go

@@ -0,0 +1,91 @@
+package test
+
+import (
+	"context"
+	"log"
+	"testing"
+	"time"
+
+	"app.yhyue.com/moapp/jyfs/rpc/filesystem"
+	"app.yhyue.com/moapp/jyfs/rpc/filesystemclient"
+	"app.yhyue.com/moapp/jyfs/rpc/internal/config"
+
+	"github.com/tal-tech/go-zero/core/conf"
+	"github.com/tal-tech/go-zero/zrpc"
+)
+
+var C config.Config
+
+func init() {
+	conf.MustLoad("./filesystem.yaml", &C)
+}
+
+// 创建域
+func Test_CreateDomain(t *testing.T) {
+	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
+	FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
+	req := &filesystem.DomainReq{Name: "xzh", MetaFields: []string{""}}
+	res, err := FileSystem.CreateDomain(ctx, req)
+	log.Println("err ", err)
+	log.Println("req ", res)
+}
+
+// 删除域
+func Test_DeleteDomain(t *testing.T) {
+	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
+	FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
+	req := &filesystem.DomainReq{Name: "xzh", MetaFields: []string{""}}
+	res, err := FileSystem.DeleteDomain(ctx, req)
+	log.Println("err ", err)
+	log.Println("req ", res)
+}
+
+// 删除文件
+func Test_DeleteFile(t *testing.T) {
+	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
+	FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
+	req := &filesystem.DomainReq{Name: "xzh", MetaFields: []string{""}}
+	res, err := FileSystem.DeleteFile(ctx, req)
+	log.Println("err ", err)
+	log.Println("req ", res)
+}
+
+// 获取文件
+func Test_GetFile(t *testing.T) {
+	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
+	FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
+	req := &filesystem.DomainReq{Name: "xzh", MetaFields: []string{""}}
+	res, err := FileSystem.DeleteDomain(ctx, req)
+	log.Println("err ", err)
+	log.Println("req ", res)
+}
+
+// 获取文件元数据
+func Test_GetFileMeta(t *testing.T) {
+	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
+	FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
+	req := &filesystem.DomainReq{Name: "xzh", MetaFields: []string{""}}
+	res, err := FileSystem.GetFileMeta(ctx, req)
+	log.Println("err ", err)
+	log.Println("req ", res)
+}
+
+// 保存文件
+func Test_SaveFile(t *testing.T) {
+	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
+	FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
+	req := &filesystem.DomainReq{Name: "xzh", MetaFields: []string{""}}
+	res, err := FileSystem.SaveFile(ctx, req)
+	log.Println("err ", err)
+	log.Println("req ", res)
+}
+
+// 更新文件元数据
+func Test_UpdateFileMeta(t *testing.T) {
+	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
+	FileSystem := filesystemclient.NewFileSystem(zrpc.MustNewClient(C.FileSystemConf))
+	req := &filesystem.DomainReq{Name: "xzh", MetaFields: []string{""}}
+	res, err := FileSystem.UpdateFileMeta(ctx, req)
+	log.Println("err ", err)
+	log.Println("req ", res)
+}

二進制
test/.DS_Store


+ 25 - 0
test/createdomain_test.go

@@ -0,0 +1,25 @@
+package test
+
+import (
+	"log"
+	"testing"
+
+	"app.yhyue.com/moapp/jyfs/api/internal"
+
+	"app.yhyue.com/moapp/jyfs/rpc/filesystem"
+	"app.yhyue.com/moapp/jyfs/rpc/filesystemclient"
+	"github.com/tal-tech/go-zero/zrpc"
+)
+
+var (
+	internal
+	fileSystemConf := config.Config.FileSystemConf
+	FileSystem = filesystemclient.NewFileSystem(zrpc.MustNewClient(fileSystemConf))
+)
+
+// 创建域
+func Test_CreateDomain(t *testing.T) {
+	var req = &filesystem.DomainReq{Name: "xzh"}
+	req := FileSystem.CreateDomain(req)
+	log.Println("req ", req)
+}

部分文件因文件數量過多而無法顯示