Browse Source

远程调用rpc

master
xyiege 5 months ago
parent
commit
c16e14361d
  1. 40
      aufs/core/sendzip.go

40
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()
}
// 将文件打包成压缩包

Loading…
Cancel
Save