From 258c2069883d9ebc56bb113e0bebe8e0acfbfdb8 Mon Sep 17 00:00:00 2001 From: crusader Date: Fri, 23 Mar 2018 12:48:20 +0900 Subject: [PATCH] ing --- glide.yaml | 2 -- protocol/json/client.go | 4 ++-- protocol/json/client_notification.go | 3 +-- protocol/json/client_response.go | 8 +++----- protocol/json/constants.go | 6 ------ protocol/json/server.go | 3 +-- protocol/json/server_request.go | 7 +++---- protocol/json/util.go | 6 +++--- 8 files changed, 13 insertions(+), 26 deletions(-) diff --git a/glide.yaml b/glide.yaml index 12cdd12..8d495b7 100644 --- a/glide.yaml +++ b/glide.yaml @@ -6,5 +6,3 @@ import: - package: gopkg.in/natefinch/npipe.v2 - package: git.loafle.net/commons_go/websocket_fasthttp - package: git.loafle.net/commons_go/util -- package: github.com/json-iterator/go - version: 1.1.3 diff --git a/protocol/json/client.go b/protocol/json/client.go index 15e9eb4..3ead2d6 100644 --- a/protocol/json/client.go +++ b/protocol/json/client.go @@ -1,11 +1,11 @@ package json import ( + "encoding/json" "io" "git.loafle.net/commons_go/rpc/codec" "git.loafle.net/commons_go/rpc/protocol" - jsoniter "github.com/json-iterator/go" ) // ---------------------------------------------------------------------------- @@ -40,7 +40,7 @@ func (cc *ClientCodec) WriteRequest(w io.Writer, method string, args []interface ID: id, } - encoder := jsoniter.NewEncoder(cc.codecSel.SelectByWriter(w).Encode(w)) + encoder := json.NewEncoder(cc.codecSel.SelectByWriter(w).Encode(w)) if err := encoder.Encode(req); nil != err { return err } diff --git a/protocol/json/client_notification.go b/protocol/json/client_notification.go index 18b4c54..0c96da2 100644 --- a/protocol/json/client_notification.go +++ b/protocol/json/client_notification.go @@ -6,7 +6,6 @@ import ( "git.loafle.net/commons_go/rpc/codec" crp "git.loafle.net/commons_go/rpc/protocol" cuej "git.loafle.net/commons_go/util/encoding/json" - jsoniter "github.com/json-iterator/go" ) // ---------------------------------------------------------------------------- @@ -56,7 +55,7 @@ func (cnc *ClientNotificationCodec) Params() ([]string, error) { if cnc.err == nil && cnc.noti.Params != nil { var values []string - if err := jsoniter.Unmarshal(*cnc.noti.Params, &values); err != nil { + if err := json.Unmarshal(*cnc.noti.Params, &values); err != nil { cnc.err = &Error{ Code: crp.E_INVALID_REQ, Message: err.Error(), diff --git a/protocol/json/client_response.go b/protocol/json/client_response.go index c4fd65d..5c53b1a 100644 --- a/protocol/json/client_response.go +++ b/protocol/json/client_response.go @@ -8,7 +8,6 @@ import ( "git.loafle.net/commons_go/rpc/codec" "git.loafle.net/commons_go/rpc/protocol" crp "git.loafle.net/commons_go/rpc/protocol" - jsoniter "github.com/json-iterator/go" ) // ---------------------------------------------------------------------------- @@ -35,7 +34,7 @@ func (crc *ClientResponseCodec) ID() interface{} { func (crc *ClientResponseCodec) Result(result interface{}) error { if nil == crc.err && nil != crc.res.Result { - if err := jsoniter.Unmarshal(*crc.res.Result, result); nil != err { + if err := json.Unmarshal(*crc.res.Result, result); nil != err { crc.err = &Error{ Code: crp.E_PARSE, Message: err.Error(), @@ -57,7 +56,7 @@ func (crc *ClientResponseCodec) Notification() (protocol.ClientNotificationCodec } noti := &clientNotification{} - err := jsoniter.Unmarshal(*crc.res.Result, noti) + err := json.Unmarshal(*crc.res.Result, noti) if nil != err { return nil, err } @@ -67,8 +66,7 @@ func (crc *ClientResponseCodec) Notification() (protocol.ClientNotificationCodec // newClientMessageCodec returns a new ClientMessageCodec. func newClientResponseCodec(r io.Reader, codec codec.Codec) (protocol.ClientResponseCodec, error) { - - decoder := jsoniter.NewDecoder(r) + decoder := json.NewDecoder(r) if nil == r { return nil, io.EOF } diff --git a/protocol/json/constants.go b/protocol/json/constants.go index 524e171..b5e4742 100644 --- a/protocol/json/constants.go +++ b/protocol/json/constants.go @@ -1,11 +1,5 @@ package json -// import ( -// jsoniter "github.com/json-iterator/go" -// ) - -// var json = jsoniter.ConfigCompatibleWithStandardLibrary - const ( Name = "jsonrpc" Version = "2.0" diff --git a/protocol/json/server.go b/protocol/json/server.go index af5135d..cbc38f9 100644 --- a/protocol/json/server.go +++ b/protocol/json/server.go @@ -6,7 +6,6 @@ import ( "git.loafle.net/commons_go/rpc/codec" "git.loafle.net/commons_go/rpc/protocol" - jsoniter "github.com/json-iterator/go" ) var null = json.RawMessage([]byte("null")) @@ -45,7 +44,7 @@ func (sc *ServerCodec) WriteNotification(w io.Writer, method string, args []inte noti := &serverNotification{Method: method, Params: params} res := &serverResponse{Version: Version, Result: noti} - encoder := jsoniter.NewEncoder(sc.codecSel.SelectByWriter(w).Encode(w)) + encoder := json.NewEncoder(sc.codecSel.SelectByWriter(w).Encode(w)) // Not sure in which case will this happen. But seems harmless. if err := encoder.Encode(res); nil != err { return err diff --git a/protocol/json/server_request.go b/protocol/json/server_request.go index 3bec25a..9f0d955 100644 --- a/protocol/json/server_request.go +++ b/protocol/json/server_request.go @@ -8,7 +8,6 @@ import ( "git.loafle.net/commons_go/rpc/protocol" crp "git.loafle.net/commons_go/rpc/protocol" cuej "git.loafle.net/commons_go/util/encoding/json" - jsoniter "github.com/json-iterator/go" ) // ---------------------------------------------------------------------------- @@ -39,7 +38,7 @@ type serverRequest struct { // newRequestCodec returns a new ServerRequestCodec. func newServerRequestCodec(r io.Reader, codec codec.Codec) (protocol.ServerRequestCodec, error) { // Decode the request body and check if RPC method is valid. - decoder := jsoniter.NewDecoder(r) + decoder := json.NewDecoder(r) if nil == r { return nil, io.EOF } @@ -119,7 +118,7 @@ func (src *ServerRequestCodec) Params() ([]string, error) { if src.err == nil && src.req.Params != nil { var values []string - if err := jsoniter.Unmarshal(*src.req.Params, &values); err != nil { + if err := json.Unmarshal(*src.req.Params, &values); err != nil { src.err = &Error{ Code: crp.E_INVALID_REQ, Message: err.Error(), @@ -155,7 +154,7 @@ func (src *ServerRequestCodec) WriteError(w io.Writer, status int, err error) er func (src *ServerRequestCodec) writeServerResponse(w io.Writer, res *serverResponse) error { // ID is null for notifications and they don't have a response. if src.req.ID != nil { - encoder := jsoniter.NewEncoder(src.codec.Encode(w)) + encoder := json.NewEncoder(src.codec.Encode(w)) // Not sure in which case will this happen. But seems harmless. if err := encoder.Encode(res); nil != err { return err diff --git a/protocol/json/util.go b/protocol/json/util.go index d31ee5d..43695d1 100644 --- a/protocol/json/util.go +++ b/protocol/json/util.go @@ -1,11 +1,11 @@ package json import ( + "encoding/json" "fmt" "reflect" cur "git.loafle.net/commons_go/util/reflect" - jsoniter "github.com/json-iterator/go" ) func convertParamsToStringArray(params []interface{}) ([]string, error) { @@ -20,7 +20,7 @@ func convertParamsToStringArray(params []interface{}) ([]string, error) { case reflect.String: values = append(values, param.(string)) case reflect.Array, reflect.Slice, reflect.Map, reflect.Struct: - b, err := jsoniter.Marshal(param) + b, err := json.Marshal(param) if nil != err { return nil, err } @@ -29,7 +29,7 @@ func convertParamsToStringArray(params []interface{}) ([]string, error) { if t.Elem().Kind() != reflect.Struct { return nil, fmt.Errorf("Pointer of param[%d] is permitted only Struct type", i) } - b, err := jsoniter.Marshal(param) + b, err := json.Marshal(param) if nil != err { return nil, err }