|
|
@ -1,11 +1,18 @@ |
|
|
package core |
|
|
package core |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
|
|
|
"encoding/json" |
|
|
"fmt" |
|
|
"fmt" |
|
|
"net/http" |
|
|
"net/http" |
|
|
"net/rpc/jsonrpc" |
|
|
"net/rpc/jsonrpc" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
type AuResp struct { |
|
|
|
|
|
Status int `json:"status"` |
|
|
|
|
|
Message string `json:"message"` |
|
|
|
|
|
Data map[string]interface{} `json:"data"` |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 文件操作
|
|
|
// 文件操作
|
|
|
func Flist(w http.ResponseWriter, r *http.Request) { |
|
|
func Flist(w http.ResponseWriter, r *http.Request) { |
|
|
// 获取需要监听的服务器
|
|
|
// 获取需要监听的服务器
|
|
|
@ -21,6 +28,8 @@ func Flist(w http.ResponseWriter, r *http.Request) { |
|
|
var reply string |
|
|
var reply string |
|
|
var args = Args{"/www/wwwroot/fsc.com", "dir"} |
|
|
var args = Args{"/www/wwwroot/fsc.com", "dir"} |
|
|
err = client.Call("FileRpcService.GetFilePath", args, &reply) |
|
|
err = client.Call("FileRpcService.GetFilePath", args, &reply) |
|
|
|
|
|
// 执行完成后退出
|
|
|
|
|
|
defer client.Close() |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
if err != nil { |
|
|
fmt.Fprintf(w, "jsonrpc call faild %v", err) |
|
|
fmt.Fprintf(w, "jsonrpc call faild %v", err) |
|
|
@ -29,5 +38,20 @@ func Flist(w http.ResponseWriter, r *http.Request) { |
|
|
// 输出内容
|
|
|
// 输出内容
|
|
|
w.Header().Set("Content-Type", "application/json") |
|
|
w.Header().Set("Content-Type", "application/json") |
|
|
// json.NewEncoder(w).Encode(dtm)
|
|
|
// json.NewEncoder(w).Encode(dtm)
|
|
|
w.Write([]byte(reply)) |
|
|
// w.Write([]byte(reply))
|
|
|
|
|
|
var m map[string]interface{} |
|
|
|
|
|
err = json.Unmarshal([]byte(reply), &m) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
fmt.Println("json.Unmarshal err:", err) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 封装json
|
|
|
|
|
|
resp := AuResp{ |
|
|
|
|
|
Status: 200, |
|
|
|
|
|
Message: "success", |
|
|
|
|
|
Data: m, |
|
|
|
|
|
} |
|
|
|
|
|
json.NewEncoder(w).Encode(resp) |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|