Exemplo n.º 1
0
// NewJSONRPCHandler makes a JSON-RPC handler for s.
func NewJSONRPCHandler(s *rpc.Server) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		defer r.Body.Close()
		w.Header().Set("Content-Type", "application/json")
		var b bytes.Buffer
		var codec = jsonrpc.NewServerCodec(&readWriteCloser{r: r.Body, w: &b})
		if err := s.ServeRequest(codec); err != nil {
			panic(err)
		}
		codec.Close()
		io.Copy(w, &b)
	})
}