1. 项目地址:
    https://github.com/valyala/gorpc
  2. 用法:
    1. server.go:
      package main
      import (
      "fmt"
      "github.com/valyala/gorpc"
      )
      func main() {
      s := &gorpc.Server{
       Addr: ":12345",
       Handler: func(clientAddr string, request interface{}) interface{} {
           event := request.(string)
           fmt.Println("客户端发送事件:" + event)
           var ret string
           switch event {
               case "do:login":
                   ret = "login:success"
               default:
                   ret = "not:allowed"
           }
           return ret
       },
      }
      s.Serve()
      }
    2. client.go:
      package main
      import (
      "fmt"
      "github.com/valyala/gorpc"
      )
      func main() {
      c := &gorpc.Client{
       Addr: "127.0.0.1:12345",
      }
      c.Start()
      resp, _ := c.Call("do:login")
      fmt.Println("服务端返回数据:",resp.(string))
      }
文档更新时间: 2020-09-26 13:45   作者:lee