From 7a421dd638f93bc9e93eb91e8260082cfb8eaed6 Mon Sep 17 00:00:00 2001 From: xc Date: Mon, 8 Sep 2025 16:54:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=81=E8=A3=85json=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aufs/core/AuFile.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/aufs/core/AuFile.go b/aufs/core/AuFile.go index f33bdad..4da4767 100644 --- a/aufs/core/AuFile.go +++ b/aufs/core/AuFile.go @@ -1,11 +1,18 @@ package core import ( + "encoding/json" "fmt" "net/http" "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) { // 获取需要监听的服务器 @@ -21,6 +28,8 @@ func Flist(w http.ResponseWriter, r *http.Request) { var reply string var args = Args{"/www/wwwroot/fsc.com", "dir"} err = client.Call("FileRpcService.GetFilePath", args, &reply) + // 执行完成后退出 + defer client.Close() if err != nil { 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") // 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) + }