1
0
mirror of https://github.com/labstack/echo.git synced 2025-02-03 13:11:39 +02:00

Using json-iterator

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2018-03-14 20:38:46 -07:00
parent 62d3587b6f
commit 20ac716d4c
4 changed files with 37 additions and 15 deletions

20
Gopkg.lock generated
View File

@ -13,6 +13,12 @@
revision = "06ea1031745cb8b3dab3f6a236daf2b0aa468b7e"
version = "v3.2.0"
[[projects]]
name = "github.com/json-iterator/go"
packages = ["."]
revision = "3353055b2a1a5ae1b6a8dfde887a524e7088f3a2"
version = "1.1.2"
[[projects]]
name = "github.com/labstack/gommon"
packages = ["bytes","color","log","random"]
@ -31,6 +37,18 @@
revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39"
version = "v0.0.3"
[[projects]]
name = "github.com/modern-go/concurrent"
packages = ["."]
revision = "bacd9c7ef1dd9b15be4a9909b8ac7a4e313eec94"
version = "1.0.3"
[[projects]]
name = "github.com/modern-go/reflect2"
packages = ["."]
revision = "1df9eeb2bb81f327b96228865c5687bc2194af3f"
version = "1.0.0"
[[projects]]
name = "github.com/pmezard/go-difflib"
packages = ["difflib"]
@ -70,6 +88,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "9c7b45e80fe353405800cf01f429b3a203cfb8d4468a04c64a908e11a98ea764"
inputs-digest = "31ef70d84624d67044a34f640845da3a27ceff5237c672c2b6265411162a00a8"
solver-name = "gps-cdcl"
solver-version = 1

View File

@ -40,3 +40,7 @@
[[constraint]]
branch = "master"
name = "golang.org/x/crypto"
[[constraint]]
name = "github.com/json-iterator/go"
version = "1.1.2"

View File

@ -2,7 +2,6 @@ package echo
import (
"bytes"
"encoding/json"
"encoding/xml"
"fmt"
"io"
@ -13,6 +12,8 @@ import (
"os"
"path/filepath"
"strings"
"github.com/json-iterator/go"
)
type (
@ -206,6 +207,10 @@ const (
indexPage = "index.html"
)
var (
jsoni = jsoniter.ConfigCompatibleWithStandardLibrary
)
func (c *context) Request() *http.Request {
return c.request
}
@ -402,7 +407,7 @@ func (c *context) JSON(code int, i interface{}) (err error) {
if c.echo.Debug || pretty {
return c.JSONPretty(code, i, " ")
}
b, err := json.Marshal(i)
b, err := jsoni.Marshal(i)
if err != nil {
return
}
@ -410,7 +415,7 @@ func (c *context) JSON(code int, i interface{}) (err error) {
}
func (c *context) JSONPretty(code int, i interface{}, indent string) (err error) {
b, err := json.MarshalIndent(i, "", indent)
b, err := jsoni.MarshalIndent(i, "", indent)
if err != nil {
return
}
@ -422,7 +427,7 @@ func (c *context) JSONBlob(code int, b []byte) (err error) {
}
func (c *context) JSONP(code int, callback string, i interface{}) (err error) {
b, err := json.Marshal(i)
b, err := jsoni.Marshal(i)
if err != nil {
return
}

15
echo.go
View File

@ -81,8 +81,7 @@ type (
Binder Binder
Validator Validator
Renderer Renderer
// Mutex sync.RWMutex
Logger Logger
Logger Logger
}
// Route contains a handler and information for matching against requests.
@ -554,10 +553,6 @@ func (e *Echo) ReleaseContext(c Context) {
// ServeHTTP implements `http.Handler` interface, which serves HTTP requests.
func (e *Echo) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Acquire lock
// e.Mutex.RLock()
// defer e.Mutex.RUnlock()
// Acquire context
c := e.pool.Get().(*context)
c.Reset(r, w)
@ -565,11 +560,11 @@ func (e *Echo) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Middleware
h := func(c Context) error {
method := r.Method
rpath := r.URL.RawPath // Raw path
if rpath == "" {
rpath = r.URL.Path
path := r.URL.RawPath
if path == "" {
path = r.URL.Path
}
e.router.Find(method, rpath, c)
e.router.Find(method, path, c)
h := c.Handler()
for i := len(e.middleware) - 1; i >= 0; i-- {
h = e.middleware[i](h)