Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧹 Use encoding/json #1851

Merged
merged 2 commits into from Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/README.md
Expand Up @@ -688,7 +688,6 @@ Copyright (c) 2019-present [Fenny](https://github.com/fenny) and [Contributors](
- [schema](https://github.com/gorilla/schema/blob/master/LICENSE)
- [isatty](https://github.com/mattn/go-isatty/blob/master/LICENSE)
- [fasthttp](https://github.com/valyala/fasthttp/blob/master/LICENSE)
- [go-json](https://github.com/goccy/go-json/blob/master/LICENSE)
- [colorable](https://github.com/mattn/go-colorable/blob/master/LICENSE)
- [fasttemplate](https://github.com/valyala/fasttemplate/blob/master/LICENSE)
- [bytebufferpool](https://github.com/valyala/bytebufferpool/blob/master/LICENSE)
Expand Down
1 change: 0 additions & 1 deletion .github/README_ckb.md
Expand Up @@ -688,7 +688,6 @@ For more articles, middlewares, examples or tools check our [awesome list](https
- [schema](https://github.com/gorilla/schema/blob/master/LICENSE)
- [isatty](https://github.com/mattn/go-isatty/blob/master/LICENSE)
- [fasthttp](https://github.com/valyala/fasthttp/blob/master/LICENSE)
- [go-json](https://github.com/goccy/go-json/blob/master/LICENSE)
- [colorable](https://github.com/mattn/go-colorable/blob/master/LICENSE)
- [fasttemplate](https://github.com/valyala/fasttemplate/blob/master/LICENSE)
- [bytebufferpool](https://github.com/valyala/bytebufferpool/blob/master/LICENSE)
Expand Down
1 change: 0 additions & 1 deletion .github/README_de.md
Expand Up @@ -658,7 +658,6 @@ Copyright (c) 2019-present [Fenny](https://github.com/fenny) and [Contributors](
- [schema](https://github.com/gorilla/schema/blob/master/LICENSE)
- [isatty](https://github.com/mattn/go-isatty/blob/master/LICENSE)
- [fasthttp](https://github.com/valyala/fasthttp/blob/master/LICENSE)
- [go-json](https://github.com/goccy/go-json/blob/master/LICENSE)
- [colorable](https://github.com/mattn/go-colorable/blob/master/LICENSE)
- [fasttemplate](https://github.com/valyala/fasttemplate/blob/master/LICENSE)
- [bytebufferpool](https://github.com/valyala/bytebufferpool/blob/master/LICENSE)
Expand Down
1 change: 0 additions & 1 deletion .github/README_es.md
Expand Up @@ -658,7 +658,6 @@ Copyright (c) 2019-presente [Fenny](https://github.com/fenny) y [contribuyentes]
- [schema](https://github.com/gorilla/schema/blob/master/LICENSE)
- [isatty](https://github.com/mattn/go-isatty/blob/master/LICENSE)
- [fasthttp](https://github.com/valyala/fasthttp/blob/master/LICENSE)
- [go-json](https://github.com/goccy/go-json/blob/master/LICENSE)
- [colorable](https://github.com/mattn/go-colorable/blob/master/LICENSE)
- [fasttemplate](https://github.com/valyala/fasttemplate/blob/master/LICENSE)
- [bytebufferpool](https://github.com/valyala/bytebufferpool/blob/master/LICENSE)
Expand Down
1 change: 0 additions & 1 deletion .github/README_fa.md
Expand Up @@ -810,7 +810,6 @@ Copyright (c) 2019-present [Fenny](https://github.com/fenny) and [Contributors](
- [schema](https://github.com/gorilla/schema/blob/master/LICENSE)
- [isatty](https://github.com/mattn/go-isatty/blob/master/LICENSE)
- [fasthttp](https://github.com/valyala/fasthttp/blob/master/LICENSE)
- [go-json](https://github.com/goccy/go-json/blob/master/LICENSE)
- [colorable](https://github.com/mattn/go-colorable/blob/master/LICENSE)
- [fasttemplate](https://github.com/valyala/fasttemplate/blob/master/LICENSE)
- [bytebufferpool](https://github.com/valyala/bytebufferpool/blob/master/LICENSE)
Expand Down
1 change: 0 additions & 1 deletion .github/README_fr.md
Expand Up @@ -660,7 +660,6 @@ Copyright (c) 2019-present [Fenny](https://github.com/fenny) and [Contributors](
- [schema](https://github.com/gorilla/schema/blob/master/LICENSE)
- [isatty](https://github.com/mattn/go-isatty/blob/master/LICENSE)
- [fasthttp](https://github.com/valyala/fasthttp/blob/master/LICENSE)
- [go-json](https://github.com/goccy/go-json/blob/master/LICENSE)
- [colorable](https://github.com/mattn/go-colorable/blob/master/LICENSE)
- [fasttemplate](https://github.com/valyala/fasttemplate/blob/master/LICENSE)
- [bytebufferpool](https://github.com/valyala/bytebufferpool/blob/master/LICENSE)
Expand Down
1 change: 0 additions & 1 deletion .github/README_he.md
Expand Up @@ -835,7 +835,6 @@ Copyright (c) 2019-present [Fenny](https://github.com/fenny) and [Contributors](
- [schema](https://github.com/gorilla/schema/blob/master/LICENSE)
- [isatty](https://github.com/mattn/go-isatty/blob/master/LICENSE)
- [fasthttp](https://github.com/valyala/fasthttp/blob/master/LICENSE)
- [go-json](https://github.com/goccy/go-json/blob/master/LICENSE)
- [colorable](https://github.com/mattn/go-colorable/blob/master/LICENSE)
- [fasttemplate](https://github.com/valyala/fasttemplate/blob/master/LICENSE)
- [bytebufferpool](https://github.com/valyala/bytebufferpool/blob/master/LICENSE)
Expand Down
1 change: 0 additions & 1 deletion .github/README_id.md
Expand Up @@ -661,7 +661,6 @@ Copyright (c) 2019-present [Fenny](https://github.com/fenny) and [Contributors](
- [schema](https://github.com/gorilla/schema/blob/master/LICENSE)
- [isatty](https://github.com/mattn/go-isatty/blob/master/LICENSE)
- [fasthttp](https://github.com/valyala/fasthttp/blob/master/LICENSE)
- [go-json](https://github.com/goccy/go-json/blob/master/LICENSE)
- [colorable](https://github.com/mattn/go-colorable/blob/master/LICENSE)
- [fasttemplate](https://github.com/valyala/fasttemplate/blob/master/LICENSE)
- [bytebufferpool](https://github.com/valyala/bytebufferpool/blob/master/LICENSE)
Expand Down
1 change: 0 additions & 1 deletion .github/README_it.md
Expand Up @@ -684,7 +684,6 @@ Copyright (c) 2019-ora [Fenny](https://github.com/fenny) e [Contributors](https:
- [schema](https://github.com/gorilla/schema/blob/master/LICENSE)
- [isatty](https://github.com/mattn/go-isatty/blob/master/LICENSE)
- [fasthttp](https://github.com/valyala/fasthttp/blob/master/LICENSE)
- [go-json](https://github.com/goccy/go-json/blob/master/LICENSE)
- [colorable](https://github.com/mattn/go-colorable/blob/master/LICENSE)
- [fasttemplate](https://github.com/valyala/fasttemplate/blob/master/LICENSE)
- [bytebufferpool](https://github.com/valyala/bytebufferpool/blob/master/LICENSE)
Expand Down
1 change: 0 additions & 1 deletion .github/README_ja.md
Expand Up @@ -663,7 +663,6 @@ Copyright (c) 2019-present [Fenny](https://github.com/fenny) and [Contributors](
- [schema](https://github.com/gorilla/schema/blob/master/LICENSE)
- [isatty](https://github.com/mattn/go-isatty/blob/master/LICENSE)
- [fasthttp](https://github.com/valyala/fasthttp/blob/master/LICENSE)
- [go-json](https://github.com/goccy/go-json/blob/master/LICENSE)
- [colorable](https://github.com/mattn/go-colorable/blob/master/LICENSE)
- [fasttemplate](https://github.com/valyala/fasttemplate/blob/master/LICENSE)
- [bytebufferpool](https://github.com/valyala/bytebufferpool/blob/master/LICENSE)
Expand Down
1 change: 0 additions & 1 deletion .github/README_ko.md
Expand Up @@ -664,7 +664,6 @@ Copyright (c) 2019-present [Fenny](https://github.com/fenny) and [Contributors](
- [schema](https://github.com/gorilla/schema/blob/master/LICENSE)
- [isatty](https://github.com/mattn/go-isatty/blob/master/LICENSE)
- [fasthttp](https://github.com/valyala/fasthttp/blob/master/LICENSE)
- [go-json](https://github.com/goccy/go-json/blob/master/LICENSE)
- [colorable](https://github.com/mattn/go-colorable/blob/master/LICENSE)
- [fasttemplate](https://github.com/valyala/fasttemplate/blob/master/LICENSE)
- [bytebufferpool](https://github.com/valyala/bytebufferpool/blob/master/LICENSE)
Expand Down
1 change: 0 additions & 1 deletion .github/README_nl.md
Expand Up @@ -664,7 +664,6 @@ Copyright (c) 2019-present [Fenny](https://github.com/fenny) and [Contributors](
- [schema](https://github.com/gorilla/schema/blob/master/LICENSE)
- [isatty](https://github.com/mattn/go-isatty/blob/master/LICENSE)
- [fasthttp](https://github.com/valyala/fasthttp/blob/master/LICENSE)
- [go-json](https://github.com/goccy/go-json/blob/master/LICENSE)
- [colorable](https://github.com/mattn/go-colorable/blob/master/LICENSE)
- [fasttemplate](https://github.com/valyala/fasttemplate/blob/master/LICENSE)
- [bytebufferpool](https://github.com/valyala/bytebufferpool/blob/master/LICENSE)
Expand Down
1 change: 0 additions & 1 deletion .github/README_pt.md
Expand Up @@ -660,7 +660,6 @@ O logo oficial foi criado por [Vic Shóstak](https://github.com/koddr) e distrib
- [schema](https://github.com/gorilla/schema/blob/master/LICENSE)
- [isatty](https://github.com/mattn/go-isatty/blob/master/LICENSE)
- [fasthttp](https://github.com/valyala/fasthttp/blob/master/LICENSE)
- [go-json](https://github.com/goccy/go-json/blob/master/LICENSE)
- [colorable](https://github.com/mattn/go-colorable/blob/master/LICENSE)
- [fasttemplate](https://github.com/valyala/fasttemplate/blob/master/LICENSE)
- [bytebufferpool](https://github.com/valyala/bytebufferpool/blob/master/LICENSE)
Expand Down
1 change: 0 additions & 1 deletion .github/README_ru.md
Expand Up @@ -667,7 +667,6 @@ Copyright (c) 2019-present [Fenny](https://github.com/fenny) and [Contributors](
- [schema](https://github.com/gorilla/schema/blob/master/LICENSE)
- [isatty](https://github.com/mattn/go-isatty/blob/master/LICENSE)
- [fasthttp](https://github.com/valyala/fasthttp/blob/master/LICENSE)
- [go-json](https://github.com/goccy/go-json/blob/master/LICENSE)
- [colorable](https://github.com/mattn/go-colorable/blob/master/LICENSE)
- [fasttemplate](https://github.com/valyala/fasttemplate/blob/master/LICENSE)
- [bytebufferpool](https://github.com/valyala/bytebufferpool/blob/master/LICENSE)
Expand Down
1 change: 0 additions & 1 deletion .github/README_sa.md
Expand Up @@ -729,7 +729,6 @@ Copyright (c) 2019-present [Fenny](https://github.com/fenny) and [Contributors](
- [schema](https://github.com/gorilla/schema/blob/master/LICENSE)
- [isatty](https://github.com/mattn/go-isatty/blob/master/LICENSE)
- [fasthttp](https://github.com/valyala/fasthttp/blob/master/LICENSE)
- [go-json](https://github.com/goccy/go-json/blob/master/LICENSE)
- [colorable](https://github.com/mattn/go-colorable/blob/master/LICENSE)
- [fasttemplate](https://github.com/valyala/fasttemplate/blob/master/LICENSE)
- [bytebufferpool](https://github.com/valyala/bytebufferpool/blob/master/LICENSE)
Expand Down
1 change: 0 additions & 1 deletion .github/README_tr.md
Expand Up @@ -657,7 +657,6 @@ Telif (c) 2019-günümüz [Fenny](https://github.com/fenny) ve [katkıda bulunan
- [schema](https://github.com/gorilla/schema/blob/master/LICENSE)
- [isatty](https://github.com/mattn/go-isatty/blob/master/LICENSE)
- [fasthttp](https://github.com/valyala/fasthttp/blob/master/LICENSE)
- [go-json](https://github.com/goccy/go-json/blob/master/LICENSE)
- [colorable](https://github.com/mattn/go-colorable/blob/master/LICENSE)
- [fasttemplate](https://github.com/valyala/fasttemplate/blob/master/LICENSE)
- [bytebufferpool](https://github.com/valyala/bytebufferpool/blob/master/LICENSE)
Expand Down
1 change: 0 additions & 1 deletion .github/README_zh-CN.md
Expand Up @@ -660,7 +660,6 @@ Copyright (c) 2019-present [Fenny](https://github.com/fenny) and [Contributors](
- [schema](https://github.com/gorilla/schema/blob/master/LICENSE)
- [isatty](https://github.com/mattn/go-isatty/blob/master/LICENSE)
- [fasthttp](https://github.com/valyala/fasthttp/blob/master/LICENSE)
- [go-json](https://github.com/goccy/go-json/blob/master/LICENSE)
- [colorable](https://github.com/mattn/go-colorable/blob/master/LICENSE)
- [fasttemplate](https://github.com/valyala/fasttemplate/blob/master/LICENSE)
- [bytebufferpool](https://github.com/valyala/bytebufferpool/blob/master/LICENSE)
Expand Down
1 change: 0 additions & 1 deletion .github/README_zh-TW.md
Expand Up @@ -660,7 +660,6 @@ Fiber 是一個以贊助維生的開源專案,像是: 網域、gitbook、netli
- [schema](https://github.com/gorilla/schema/blob/master/LICENSE)
- [isatty](https://github.com/mattn/go-isatty/blob/master/LICENSE)
- [fasthttp](https://github.com/valyala/fasthttp/blob/master/LICENSE)
- [go-json](https://github.com/goccy/go-json/blob/master/LICENSE)
- [colorable](https://github.com/mattn/go-colorable/blob/master/LICENSE)
- [fasttemplate](https://github.com/valyala/fasttemplate/blob/master/LICENSE)
- [bytebufferpool](https://github.com/valyala/bytebufferpool/blob/master/LICENSE)
Expand Down
3 changes: 2 additions & 1 deletion app.go
Expand Up @@ -29,8 +29,9 @@ import (
"text/tabwriter"
"time"

"encoding/json"

"github.com/gofiber/fiber/v2/internal/colorable"
"github.com/gofiber/fiber/v2/internal/go-json"
"github.com/gofiber/fiber/v2/internal/isatty"
"github.com/gofiber/fiber/v2/utils"
"github.com/valyala/fasthttp"
Expand Down
3 changes: 2 additions & 1 deletion client.go
Expand Up @@ -16,7 +16,8 @@ import (
"sync"
"time"

"github.com/gofiber/fiber/v2/internal/go-json"
"encoding/json"

"github.com/gofiber/fiber/v2/utils"
"github.com/valyala/fasthttp"
)
Expand Down
65 changes: 3 additions & 62 deletions client_test.go
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"crypto/tls"
"encoding/base64"
stdjson "encoding/json"
"errors"
"fmt"
"io"
Expand All @@ -17,9 +16,9 @@ import (
"testing"
"time"

"github.com/gofiber/fiber/v2/internal/go-json"
"encoding/json"

"github.com/gofiber/fiber/v2/internal/tlstest"
"github.com/gofiber/fiber/v2/internal/uuid"
"github.com/gofiber/fiber/v2/utils"
"github.com/valyala/fasthttp/fasthttputil"
)
Expand Down Expand Up @@ -623,64 +622,6 @@ func Test_Client_Agent_RetryIf(t *testing.T) {
utils.AssertEqual(t, 0, len(errs))
}

func Test_Client_Stdjson_Gojson(t *testing.T) {
type User struct {
Account *string `json:"account"`
Password *string `json:"password"`
Nickname *string `json:"nickname"`
Address *string `json:"address,omitempty"`
Friends []*User `json:"friends,omitempty"`
}
user1Account, user1Password, user1Nickname := "abcdef", "123456", "user1"
user1 := &User{
Account: &user1Account,
Password: &user1Password,
Nickname: &user1Nickname,
Address: nil,
}
user2Account, user2Password, user2Nickname := "ghijkl", "123456", "user2"
user2 := &User{
Account: &user2Account,
Password: &user2Password,
Nickname: &user2Nickname,
Address: nil,
}
user1.Friends = []*User{user2}
expected, err := stdjson.Marshal(user1)
utils.AssertEqual(t, nil, err)

got, err := json.Marshal(user1)
utils.AssertEqual(t, nil, err)

utils.AssertEqual(t, expected, got)

type config struct {
// debug enable a debug logging.
debug bool
// log used for logging on debug mode.
log func(...interface{})
}

type res struct {
config `json:"-"`
// ID of the ent.
ID uuid.UUID `json:"id,omitempty"`
}

u := uuid.New()
test := res{
ID: u,
}

expected, err = stdjson.Marshal(test)
utils.AssertEqual(t, nil, err)

got, err = json.Marshal(test)
utils.AssertEqual(t, nil, err)

utils.AssertEqual(t, expected, got)
}

func Test_Client_Agent_Json(t *testing.T) {
handler := func(c *Ctx) error {
utils.AssertEqual(t, MIMEApplicationJSON, string(c.Request().Header.ContentType()))
Expand Down Expand Up @@ -1164,7 +1105,7 @@ func Test_Client_Agent_Struct(t *testing.T) {
utils.AssertEqual(t, StatusOK, code)
utils.AssertEqual(t, `{"success"`, string(body))
utils.AssertEqual(t, 1, len(errs))
utils.AssertEqual(t, "expected colon after object key", errs[0].Error())
utils.AssertEqual(t, "unexpected end of JSON input", errs[0].Error())
})
}

Expand Down
3 changes: 2 additions & 1 deletion ctx.go
Expand Up @@ -23,9 +23,10 @@ import (
"text/template"
"time"

"encoding/json"

"github.com/gofiber/fiber/v2/internal/bytebufferpool"
"github.com/gofiber/fiber/v2/internal/dictpool"
"github.com/gofiber/fiber/v2/internal/go-json"
"github.com/gofiber/fiber/v2/internal/schema"
"github.com/gofiber/fiber/v2/utils"
"github.com/valyala/fasthttp"
Expand Down
3 changes: 2 additions & 1 deletion error.go
@@ -1,7 +1,8 @@
package fiber

import (
"github.com/gofiber/fiber/v2/internal/go-json/errors"
errors "encoding/json"

"github.com/gofiber/fiber/v2/internal/schema"
)

Expand Down
3 changes: 2 additions & 1 deletion error_test.go
Expand Up @@ -4,7 +4,8 @@ import (
"errors"
"testing"

jerrors "github.com/gofiber/fiber/v2/internal/go-json/errors"
jerrors "encoding/json"

"github.com/gofiber/fiber/v2/internal/schema"
"github.com/gofiber/fiber/v2/utils"
)
Expand Down
21 changes: 0 additions & 21 deletions internal/go-json/LICENSE

This file was deleted.