|
@@ -3,12 +3,15 @@ package test
|
|
import (
|
|
import (
|
|
"app.yhyue.com/moapp/jyfs/rpc/filesystem"
|
|
"app.yhyue.com/moapp/jyfs/rpc/filesystem"
|
|
"app.yhyue.com/moapp/jyfs/rpc/filesystemclient"
|
|
"app.yhyue.com/moapp/jyfs/rpc/filesystemclient"
|
|
|
|
+ "bytes"
|
|
|
|
+ "compress/gzip"
|
|
"fmt"
|
|
"fmt"
|
|
"github.com/gogf/gf/v2/os/gctx"
|
|
"github.com/gogf/gf/v2/os/gctx"
|
|
"github.com/zeromicro/go-zero/core/discov"
|
|
"github.com/zeromicro/go-zero/core/discov"
|
|
"github.com/zeromicro/go-zero/zrpc"
|
|
"github.com/zeromicro/go-zero/zrpc"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc"
|
|
"log"
|
|
"log"
|
|
|
|
+ "os"
|
|
"testing"
|
|
"testing"
|
|
)
|
|
)
|
|
|
|
|
|
@@ -18,22 +21,41 @@ var (
|
|
|
|
|
|
func Test_FileUpload(t *testing.T) {
|
|
func Test_FileUpload(t *testing.T) {
|
|
log.Println("-------------")
|
|
log.Println("-------------")
|
|
|
|
+ file, err := os.Open("./2.txt")
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ defer file.Close()
|
|
|
|
+ // FileInfo:
|
|
|
|
+ stats, err := file.Stat()
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ // []byte
|
|
|
|
+ data := make([]byte, stats.Size())
|
|
|
|
+ count, err := file.Read(data)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ log.Println(count)
|
|
|
|
+ suffix := "txt"
|
|
//获取附件后上传oss
|
|
//获取附件后上传oss
|
|
fr := &filesystem.SaveFileReq{
|
|
fr := &filesystem.SaveFileReq{
|
|
Domain: Domain,
|
|
Domain: Domain,
|
|
- FileId: fmt.Sprintf("%s.%s", "101010", "doc"),
|
|
|
|
|
|
+ FileId: fmt.Sprintf("%s.%s", "101010003", suffix),
|
|
Meta: map[string]string{
|
|
Meta: map[string]string{
|
|
- "docName": "101020",
|
|
|
|
- "docSuffix": "doc",
|
|
|
|
- "docSize": "24",
|
|
|
|
|
|
+ "docName": "101010003",
|
|
|
|
+ "docSuffix": suffix,
|
|
|
|
+ "docSize": "1024",
|
|
},
|
|
},
|
|
- RawFileContent: []byte("我是中国人"),
|
|
|
|
|
|
+ RawFileContent: CompressWithGzip(data),
|
|
|
|
+ Source: "docin",
|
|
}
|
|
}
|
|
if fr != nil && len(fr.RawFileContent) > 0 {
|
|
if fr != nil && len(fr.RawFileContent) > 0 {
|
|
conf := zrpc.RpcClientConf{
|
|
conf := zrpc.RpcClientConf{
|
|
Etcd: discov.EtcdConf{
|
|
Etcd: discov.EtcdConf{
|
|
Key: "moapp.filesystem.rpc",
|
|
Key: "moapp.filesystem.rpc",
|
|
- Hosts: []string{"192.168.3.206:2379"},
|
|
|
|
|
|
+ Hosts: []string{"127.0.0.1:2379"},
|
|
},
|
|
},
|
|
}
|
|
}
|
|
grpcOpts := []zrpc.ClientOption{
|
|
grpcOpts := []zrpc.ClientOption{
|
|
@@ -53,12 +75,24 @@ func Test_GetFile(t *testing.T) {
|
|
jyFilelLib := filesystemclient.NewFileSystem(zrpc.MustNewClient(zrpc.RpcClientConf{
|
|
jyFilelLib := filesystemclient.NewFileSystem(zrpc.MustNewClient(zrpc.RpcClientConf{
|
|
Etcd: discov.EtcdConf{
|
|
Etcd: discov.EtcdConf{
|
|
Key: "moapp.filesystem.rpc",
|
|
Key: "moapp.filesystem.rpc",
|
|
- Hosts: []string{"192.168.3.206:2379"},
|
|
|
|
|
|
+ Hosts: []string{"127.0.0.1:2379"},
|
|
},
|
|
},
|
|
}))
|
|
}))
|
|
resp, err := jyFilelLib.GetOssUril(gctx.New(), &filesystem.LoadFileReq{
|
|
resp, err := jyFilelLib.GetOssUril(gctx.New(), &filesystem.LoadFileReq{
|
|
Domain: Domain,
|
|
Domain: Domain,
|
|
- FileId: "335a98b93b81dd3a0488a1eecac55d4a.pdf",
|
|
|
|
|
|
+ FileId: "101010003.txt",
|
|
})
|
|
})
|
|
log.Println(resp, "-----", err)
|
|
log.Println(resp, "-----", err)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func CompressWithGzip(data []byte) []byte {
|
|
|
|
+ var buf bytes.Buffer
|
|
|
|
+ gzipW := gzip.NewWriter(&buf)
|
|
|
|
+ if _, err := gzipW.Write(data); err != nil {
|
|
|
|
+ return nil
|
|
|
|
+ }
|
|
|
|
+ if err := gzipW.Close(); err != nil {
|
|
|
|
+ return nil
|
|
|
|
+ }
|
|
|
|
+ return buf.Bytes()
|
|
|
|
+}
|