From c16e14361d28b633ef2f27060e924341b855e1c8 Mon Sep 17 00:00:00 2001 From: xc Date: Tue, 16 Sep 2025 18:15:49 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=9C=E7=A8=8B=E8=B0=83=E7=94=A8rpc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aufs/core/sendzip.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/aufs/core/sendzip.go b/aufs/core/sendzip.go index 49c44a7..ef6335f 100644 --- a/aufs/core/sendzip.go +++ b/aufs/core/sendzip.go @@ -6,21 +6,61 @@ import ( "fmt" "net" "net/http" + "net/rpc/jsonrpc" "path" "path/filepath" "strings" "time" ) +// 压缩文件 +type ZipBlock struct { + Curpath string // 当前路径 + SelFile []string // 选中的文件 +} + // 远程调用压缩包 func SendZip(w http.ResponseWriter, r *http.Request) { r.ParseForm() // 文件 zipfarr := r.Form["sfiles"] + // 选中的路径,可以为空 + wtculpath := r.Form["curpath"] // 服务器ip地址 serip := r.Form["serverip"] + if serip[0] == "" { + http.Error(w, "remote server ip is blank!", http.StatusInternalServerError) + return + } + // 构建 + zipblock := ZipBlock{ + Curpath: wtculpath[0], + SelFile: zipfarr, + } + // 从serip 切割出ip 和端口 + // splitip := strings.Split(serip[0], ":") + // if len(splitip) != 2 { + // http.Error(w, "remote server ip is error!", http.StatusInternalServerError) + // return + // } + // srcip := splitip[0] + // sport := splitip[1] + // + // service := fmt.Sprintf("%v:%v", srcip, sport) + service := serip[0] + client, err := jsonrpc.Dial("tcp", service) + if err != nil { + fmt.Fprintf(w, "jsonrpc dial faild %v", err) + return + } + // 调用远程方法 + var reply string + // var args = Args{"/www/wwwroot/fsc.com", "dir"} + err = client.Call("FileRpcService.GetFilePath", zipblock, &reply) + // 执行完成后退出 + defer client.Close() } // 将文件打包成压缩包