服务端

  1. func main() {
  2. rpc.RegisterName("HelloService", new(HelloService))
  3. http.HandleFunc("/jsonrpc", func(w http.ResponseWriter, r *http.Request) {
  4. var conn io.ReadWriteCloser = struct {
  5. io.Writer
  6. io.ReadCloser
  7. }{
  8. ReadCloser: r.Body,
  9. Writer: w,
  10. }
  11. rpc.ServeRequest(jsonrpc.NewServerCodec(conn))
  12. })
  13. http.ListenAndServe(":1234", nil)
  14. }