Skip to content

Commit 92d5184

Browse files
committed
Update README.md
1 parent f43be2d commit 92d5184

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

README.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
[![Test Coverage](https://api.codeclimate.com/v1/badges/e820b394cdbd47103165/test_coverage)](https://codeclimate.com/github/osamingo/jsonrpc/test_coverage)
66
[![Go Report Card](https://goreportcard.com/badge/osamingo/jsonrpc)](https://goreportcard.com/report/osamingo/jsonrpc)
77
[![codebeat badge](https://codebeat.co/badges/cbd0290d-200b-4693-80dc-296d9447c35b)](https://codebeat.co/projects/github-com-osamingo-jsonrpc)
8-
[![Maintainability](https://api.codeclimate.com/v1/badges/e820b394cdbd47103165/maintainability)](https://codeclimate.com/github/osamingo/jsonrpc/maintainability)
98
[![GoDoc](https://godoc.org/github.com/osamingo/jsonrpc?status.svg)](https://godoc.org/github.com/osamingo/jsonrpc)
109
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/osamingo/jsonrpc/master/LICENSE)
1110

@@ -31,11 +30,15 @@ $ go get -u github.com/osamingo/jsonrpc
3130
package main
3231

3332
import (
33+
"bytes"
3434
"context"
35-
"encoding/json"
35+
"io"
3636
"log"
3737
"net/http"
38+
"net/http/httptest"
39+
"os"
3840

41+
"github.com/intel-go/fastjson"
3942
"github.com/osamingo/jsonrpc"
4043
)
4144

@@ -49,7 +52,7 @@ type (
4952
}
5053
)
5154

52-
func (h EchoHandler) ServeJSONRPC(c context.Context, params *json.RawMessage) (interface{}, *Error) {
55+
func (h EchoHandler) ServeJSONRPC(c context.Context, params *fastjson.RawMessage) (interface{}, *jsonrpc.Error) {
5356

5457
var p EchoParams
5558
if err := jsonrpc.Unmarshal(params, &p); err != nil {
@@ -71,7 +74,23 @@ func main() {
7174

7275
http.Handle("/jrpc", mr)
7376
http.HandleFunc("/jrpc/debug", mr.ServeDebug)
74-
if err := http.ListenAndServe(":8080", nil); err != nil {
77+
78+
srv := httptest.NewServer(http.DefaultServeMux)
79+
defer srv.Close()
80+
81+
resp, err := http.Post(srv.URL+"/jrpc", "application/json", bytes.NewBufferString(`{
82+
"jsonrpc": "2.0",
83+
"method": "Main.Echo",
84+
"params": {
85+
"name": "John Doe"
86+
},
87+
"id": "243a718a-2ebb-4e32-8cc8-210c39e8a14b"
88+
}`))
89+
if err != nil {
90+
log.Fatalln(err)
91+
}
92+
defer resp.Body.Close()
93+
if _, err := io.Copy(os.Stdout, resp.Body); err != nil {
7594
log.Fatalln(err)
7695
}
7796
}

0 commit comments

Comments
 (0)