golang jsonrpc

golang jsonrpc,第1张

概述package mainimport ( "github.com/streadway/amqp" "log" "net" "net/rpc" "net/rpc/jsonrpc" "os" "time")type MPMsg struct {}func (mpMsg *MPMsg) Handle(args *map[string
package mainimport (    "github.com/streaDWay/amqp"    "log"    "net"    "net/rpc"    "net/rpc/Jsonrpc"    "os"    "time")type MPMsg struct {}func (mpMsg *MPMsg) Handle(args *map[string]interface{},reply *map[string]interface{}) error {    *reply = map[string]interface{}{}    return nil }func main() {    lf,_ := os.Openfile("/var/log/"+time.Now().Format("2006-01-02T15:04:05")+".log",os.O_APPEND|os.O_CREATE|os.O_RDWR,0666)    defer lf.Close()    log.Setoutput(lf)    mpMsg := new(MPMsg)    rpc.Register(mpMsg)    addr,_ := net.ResolveTCPAddr("tcp",":135")    ln,e := net.ListenTCP("tcp",addr)    if e != nil {        panic(e)    }       for {        conn,e := ln.Accept()        if e != nil {            continue        }        go Jsonrpc.ServeConn(conn)    }   }



    // RPC calls.    rpcclIEnt,e := Jsonrpc.Dial("tcp","2d1c07f4-8d2d-11e5-bf81-54ee755d5aba:135")    if e != nil {        log.Println("Error dail rpc server:",e)        http.Error(w,e.Error(),http.StatusInternalServerError)        return    }       var reply map[string]interface{}    e = rpcclIEnt.Call("MPMsg.Handle",msg,&reply)    if e != nil {        log.Println("Error call rpc method:",http.StatusInternalServerError)        return    } 
总结

以上是内存溢出为你收集整理的golang jsonrpc全部内容,希望文章能够帮你解决golang jsonrpc所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1286067.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存