Browse Source

直接输出二进制

master
xyiege 7 months ago
parent
commit
a976e5fc89
  1. 31
      aufs/core/sysmonitor.go

31
aufs/core/sysmonitor.go

@ -2,7 +2,7 @@ package core
import ( import (
"aufs/proto/pb" "aufs/proto/pb"
"encoding/json" "encoding/base64"
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
@ -108,19 +108,26 @@ func SysMonitor(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
} }
// ver:0821
// 输出proto
encdata := base64.StdEncoding.EncodeToString(hdinfo)
w.Header().Set("content-type", "application/x-protobuf")
w.Write([]byte(encdata))
// make json string // make json string
jsondata, err := json.Marshal(hdinfo) // jsondata, err := json.Marshal(hdinfo)
if err != nil { // if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) // http.Error(w, err.Error(), http.StatusInternalServerError)
} // }
w.Header().Set("Content-Type", "application/json")
// w.Header().Set("Content-Type", "application/json")
// 生成json数据 // 生成json数据
jsondata, err = json.Marshal(SysResp{ // jsondata, err = json.Marshal(SysResp{
Status: 0, // Status: 0,
Message: "success", // Message: "success",
Data: hdinfo, // Data: hdinfo,
}) // })
// //
w.Write(jsondata) // w.Write(jsondata)
} }

Loading…
Cancel
Save