Browse Source

rpc服务端调整

master
xyiege 6 months ago
parent
commit
602c3ed958
  1. 10
      aufs/core/dtmem.go
  2. 5
      scagent/core/JsonRpc.go
  3. 3
      scagent/main.go

10
aufs/core/dtmem.go

@ -39,12 +39,20 @@ func Dtmem(w http.ResponseWriter, r *http.Request) {
var reply string var reply string
var args = Args{"D:\\aaa"} var args = Args{"D:\\aaa"}
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)
// replyJson, err := json.Marshal(reply)
// if err != nil {
// fmt.Fprintf(w, "json marshal faild %v", err)
// return
// }
// 打印返回值 // 打印返回值
fmt.Fprintf(w, "jsonrpc call success, reply: %d", reply) // fmt.Fprintf(w, "jsonrpc call success, reply: %v", replyJson)
// 内存动态 // 内存动态
dtm := Dtm{ dtm := Dtm{

5
scagent/core/JsonRpc.go

@ -20,7 +20,7 @@ type Reply struct {
} }
// 返回的json数据 // 返回的json数据
type FileRpc string type FileRpcService struct{}
// 返回的文件json结构体 // 返回的文件json结构体
type FloopJson struct { type FloopJson struct {
@ -35,7 +35,7 @@ type FlpList struct {
} }
// 获取文件路径 // 获取文件路径
func (f *FileRpc) GetFilePath(args *Args, replay *Reply) error { func (f *FileRpcService) GetFilePath(args *Args, replay *Reply) error {
rootDir := args.FilePath rootDir := args.FilePath
logger := util.NewProductionLogger() logger := util.NewProductionLogger()
defer logger.Sync() defer logger.Sync()
@ -81,5 +81,6 @@ func (f *FileRpc) GetFilePath(args *Args, replay *Reply) error {
// fmt.Printf("jsonStr: %s\n", jsonStr) // fmt.Printf("jsonStr: %s\n", jsonStr)
replay.Redata = string(jsonStr) replay.Redata = string(jsonStr)
//
return nil return nil
} }

3
scagent/main.go

@ -52,7 +52,7 @@ func main() {
// 检查是否以守护进程方式运行 // 检查是否以守护进程方式运行
if isDaemon() { if isDaemon() {
// 以守护进程方式运行 // 以守护进程方式运行
jrpc := new(core.FileRpc) jrpc := new(core.FileRpcService)
// 注册服务名 // 注册服务名
err := rpc.RegisterName("FileRpcService", jrpc) err := rpc.RegisterName("FileRpcService", jrpc)
if err != nil { if err != nil {
@ -74,6 +74,7 @@ func main() {
logger.Error("ListenTCP failed", zap.Error(err)) logger.Error("ListenTCP failed", zap.Error(err))
return return
} }
defer listenr.Close()
for { for {
conn, err := listenr.Accept() conn, err := listenr.Accept()

Loading…
Cancel
Save