Browse Source

完成rpc测试

master
xyiege 5 months ago
parent
commit
403866046a
  1. 22
      aufs/core/dtmem.go

22
aufs/core/dtmem.go

@ -1,7 +1,6 @@
package core package core
import ( import (
"encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"net/rpc/jsonrpc" "net/rpc/jsonrpc"
@ -29,7 +28,7 @@ func Dtmem(w http.ResponseWriter, r *http.Request) {
runtime.ReadMemStats(&m) runtime.ReadMemStats(&m)
// 测试JSONRPC // 测试JSONRPC
service := "192.168.66.212:9098" service := "192.168.66.16:9098"
client, err := jsonrpc.Dial("tcp", service) client, err := jsonrpc.Dial("tcp", service)
if err != nil { if err != nil {
fmt.Fprintf(w, "jsonrpc dial faild %v", err) fmt.Fprintf(w, "jsonrpc dial faild %v", err)
@ -37,15 +36,15 @@ func Dtmem(w http.ResponseWriter, r *http.Request) {
} }
// 调用远程方法 // 调用远程方法
var reply string var reply string
var args = Args{"D:\\aaa"} var args = Args{"/www/xt"}
err = client.Call("FileRpcService.GetFilePath", args, &reply) err = client.Call("FileRpcService.GetFilePath", args, &reply)
if err != nil { if err != nil {
fmt.Fprintf(w, "jsonrpc call faild %v", err) fmt.Fprintf(w, "jsonrpc call faild %v", err)
return return
} }
fmt.Printf("reply: %v", reply) // fmt.Printf("reply: %v", reply)
// replyJson, err := json.Marshal(reply) //replyJson, err := json.Marshal(reply)
// if err != nil { // if err != nil {
// fmt.Fprintf(w, "json marshal faild %v", err) // fmt.Fprintf(w, "json marshal faild %v", err)
// return // return
@ -55,15 +54,14 @@ func Dtmem(w http.ResponseWriter, r *http.Request) {
// fmt.Fprintf(w, "jsonrpc call success, reply: %v", replyJson) // fmt.Fprintf(w, "jsonrpc call success, reply: %v", replyJson)
// 内存动态 // 内存动态
dtm := Dtm{ // dtm := Dtm{
TotalAlloc: fmt.Sprintf("%d", m.TotalAlloc), // TotalAlloc: fmt.Sprintf("%d", m.TotalAlloc),
// Alloc: fmt.Sprintf("%v MB", m.Alloc/1024),
Alloc: fmt.Sprintf("%v MB", m.Alloc/1024), // }
}
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))
// //
// jsonobj, err := json.Marshal(m) // jsonobj, err := json.Marshal(m)
// if err != nil { // if err != nil {

Loading…
Cancel
Save