新Sir

导航

 

 

 

package main

import (
    "io"
    "net/http"
    "net/rpc"
    "net/rpc/jsonrpc"
)

type HelloService struct {
}

func (p *HelloService) Hello(request string, reply *string) error {
    *reply = "Hello:" + request
    return nil

}

func main() {
    rpc.RegisterName("HelloService", new(HelloService))
    http.HandleFunc("/jsonrpc", func(w http.ResponseWriter, r *http.Request) {

        var conn io.ReadWriteCloser = struct {
            io.Writer
            io.ReadCloser
        }{
            w,
            r.Body,
        }

        rpc.ServeRequest(jsonrpc.NewServerCodec(conn))

    })

    http.ListenAndServe(":7777", nil)

}

 

 

posted on 2022-05-06 15:21  新Sir  阅读(82)  评论(0编辑  收藏  举报