diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-03-21 09:55:16 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-21 09:55:16 +0000 |
commit | aafa0af51ff0c9e504486b593d45fcc0e3c778fc (patch) | |
tree | 92f4aaf0ee8855385780d4e6d35adca44634eba0 /service/http | |
parent | ca497b21bcc33361867d16e1709c55f0313128a7 (diff) | |
parent | a3f07d7bc55031cacccfd3dcbdf93d7e53d3479c (diff) |
Merge #282
282: Replace std json package with github.com/json-iterator/go r=48d90782 a=48d90782
resolves #281
1. Add `go vendor` command to Makefile as workaround for php vendor folder + go vendor folder hack
2. Use faster json package instead of std
3. Update GHA
Co-authored-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'service/http')
-rw-r--r-- | service/http/config_test.go | 7 | ||||
-rw-r--r-- | service/http/handler_test.go | 8 | ||||
-rw-r--r-- | service/http/request.go | 7 | ||||
-rw-r--r-- | service/http/response.go | 5 | ||||
-rw-r--r-- | service/http/rpc_test.go | 7 | ||||
-rw-r--r-- | service/http/service_test.go | 8 | ||||
-rw-r--r-- | service/http/uploads.go | 5 | ||||
-rw-r--r-- | service/http/uploads_test.go | 5 |
8 files changed, 31 insertions, 21 deletions
diff --git a/service/http/config_test.go b/service/http/config_test.go index d8b92247..d95e0995 100644 --- a/service/http/config_test.go +++ b/service/http/config_test.go @@ -1,7 +1,7 @@ package http import ( - "encoding/json" + json "github.com/json-iterator/go" "github.com/spiral/roadrunner" "github.com/spiral/roadrunner/service" "github.com/stretchr/testify/assert" @@ -13,7 +13,10 @@ import ( type mockCfg struct{ cfg string } func (cfg *mockCfg) Get(name string) service.Config { return nil } -func (cfg *mockCfg) Unmarshal(out interface{}) error { return json.Unmarshal([]byte(cfg.cfg), out) } +func (cfg *mockCfg) Unmarshal(out interface{}) error { + j := json.ConfigCompatibleWithStandardLibrary + return j.Unmarshal([]byte(cfg.cfg), out) +} func Test_Config_Hydrate_Error1(t *testing.T) { cfg := &mockCfg{`{"address": "localhost:8080"}`} diff --git a/service/http/handler_test.go b/service/http/handler_test.go index 994a663c..cb1cd728 100644 --- a/service/http/handler_test.go +++ b/service/http/handler_test.go @@ -644,7 +644,7 @@ func TestHandler_FormData_POST(t *testing.T) { t.Errorf("error listening the interface: error %v", err) } }() - time.Sleep(time.Millisecond * 10) + time.Sleep(time.Millisecond * 500) form := url.Values{} @@ -860,7 +860,7 @@ func TestHandler_FormData_PUT(t *testing.T) { t.Errorf("error listening the interface: error %v", err) } }() - time.Sleep(time.Millisecond * 10) + time.Sleep(time.Millisecond * 500) form := url.Values{} @@ -1124,7 +1124,7 @@ func TestHandler_Multipart_PUT(t *testing.T) { t.Errorf("error listening the interface: error %v", err) } }() - time.Sleep(time.Millisecond * 10) + time.Sleep(time.Millisecond * 500) var mb bytes.Buffer w := multipart.NewWriter(&mb) @@ -1241,7 +1241,7 @@ func TestHandler_Multipart_PATCH(t *testing.T) { t.Errorf("error listening the interface: error %v", err) } }() - time.Sleep(time.Millisecond * 10) + time.Sleep(time.Millisecond * 500) var mb bytes.Buffer w := multipart.NewWriter(&mb) diff --git a/service/http/request.go b/service/http/request.go index 630e26f6..acf80893 100644 --- a/service/http/request.go +++ b/service/http/request.go @@ -1,8 +1,8 @@ package http import ( - "encoding/json" "fmt" + json "github.com/json-iterator/go" "github.com/sirupsen/logrus" "github.com/spiral/roadrunner" "github.com/spiral/roadrunner/service/http/attributes" @@ -135,12 +135,13 @@ func (r *Request) Close(log *logrus.Logger) { func (r *Request) Payload() (p *roadrunner.Payload, err error) { p = &roadrunner.Payload{} - if p.Context, err = json.Marshal(r); err != nil { + j := json.ConfigCompatibleWithStandardLibrary + if p.Context, err = j.Marshal(r); err != nil { return nil, err } if r.Parsed { - if p.Body, err = json.Marshal(r.body); err != nil { + if p.Body, err = j.Marshal(r.body); err != nil { return nil, err } } else if r.body != nil { diff --git a/service/http/response.go b/service/http/response.go index 16434a7c..0942b3d2 100644 --- a/service/http/response.go +++ b/service/http/response.go @@ -1,7 +1,7 @@ package http import ( - "encoding/json" + json "github.com/json-iterator/go" "io" "net/http" "strings" @@ -24,7 +24,8 @@ type Response struct { // NewResponse creates new response based on given rr payload. func NewResponse(p *roadrunner.Payload) (*Response, error) { r := &Response{body: p.Body} - if err := json.Unmarshal(p.Context, r); err != nil { + j := json.ConfigCompatibleWithStandardLibrary + if err := j.Unmarshal(p.Context, r); err != nil { return nil, err } diff --git a/service/http/rpc_test.go b/service/http/rpc_test.go index c73f2a91..9f56e2cd 100644 --- a/service/http/rpc_test.go +++ b/service/http/rpc_test.go @@ -1,7 +1,7 @@ package http import ( - "encoding/json" + json "github.com/json-iterator/go" "github.com/sirupsen/logrus" "github.com/sirupsen/logrus/hooks/test" "github.com/spiral/roadrunner/service" @@ -93,10 +93,11 @@ func Test_RPC_Unix(t *testing.T) { c.Register(ID, &Service{}) sock := `unix://` + os.TempDir() + `/rpc.unix` - j, _ := json.Marshal(sock) + j := json.ConfigCompatibleWithStandardLibrary + data, _ := j.Marshal(sock) assert.NoError(t, c.Init(&testCfg{ - rpcCfg: `{"enable":true, "listen":` + string(j) + `}`, + rpcCfg: `{"enable":true, "listen":` + string(data) + `}`, httpCfg: `{ "enable": true, "address": ":6032", diff --git a/service/http/service_test.go b/service/http/service_test.go index 1d8af9c0..53dbb3df 100644 --- a/service/http/service_test.go +++ b/service/http/service_test.go @@ -1,7 +1,7 @@ package http import ( - "encoding/json" + json "github.com/json-iterator/go" "github.com/sirupsen/logrus" "github.com/sirupsen/logrus/hooks/test" "github.com/spiral/roadrunner" @@ -43,7 +43,8 @@ func (cfg *testCfg) Get(name string) service.Config { return nil } func (cfg *testCfg) Unmarshal(out interface{}) error { - return json.Unmarshal([]byte(cfg.target), out) + j := json.ConfigCompatibleWithStandardLibrary + return j.Unmarshal([]byte(cfg.target), out) } func Test_Service_NoConfig(t *testing.T) { @@ -554,7 +555,8 @@ func Test_Service_Error4(t *testing.T) { func tmpDir() string { p := os.TempDir() - r, _ := json.Marshal(p) + j := json.ConfigCompatibleWithStandardLibrary + r, _ := j.Marshal(p) return string(r) } diff --git a/service/http/uploads.go b/service/http/uploads.go index 8a46f230..39a9eaf2 100644 --- a/service/http/uploads.go +++ b/service/http/uploads.go @@ -1,8 +1,8 @@ package http import ( - "encoding/json" "fmt" + json "github.com/json-iterator/go" "github.com/sirupsen/logrus" "io" "io/ioutil" @@ -42,7 +42,8 @@ type Uploads struct { // MarshalJSON marshal tree tree into JSON. func (u *Uploads) MarshalJSON() ([]byte, error) { - return json.Marshal(u.tree) + j := json.ConfigCompatibleWithStandardLibrary + return j.Marshal(u.tree) } // Open moves all uploaded files to temp directory, return error in case of issue with temp directory. File errors diff --git a/service/http/uploads_test.go b/service/http/uploads_test.go index 1890c02b..08177c72 100644 --- a/service/http/uploads_test.go +++ b/service/http/uploads_test.go @@ -5,8 +5,8 @@ import ( "context" "crypto/md5" "encoding/hex" - "encoding/json" "fmt" + json "github.com/json-iterator/go" "github.com/spiral/roadrunner" "github.com/stretchr/testify/assert" "io" @@ -424,7 +424,8 @@ func fileString(f string, errNo int, mime string) string { v.Size = 0 } - r, err := json.Marshal(v) + j := json.ConfigCompatibleWithStandardLibrary + r, err := j.Marshal(v) if err != nil { fmt.Println(fmt.Errorf("error marshalling fInfo, error: %v", err)) } |