Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion encoding/form/form.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func decodeMultipartForm(ctx *fasthttp.RequestCtx, v any) error {
if err != nil {
return err
}

return dec.Decode(decoder.Map(f.Value), v)
}

Expand Down
13 changes: 2 additions & 11 deletions encoding/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,9 @@ package json
import (
"github.com/abemedia/go-don/encoding"
"github.com/goccy/go-json"
"github.com/valyala/fasthttp"
)

func decodeJSON(ctx *fasthttp.RequestCtx, v any) error {
return json.NewDecoder(ctx.RequestBodyStream()).Decode(v)
}

func encodeJSON(ctx *fasthttp.RequestCtx, v any) error {
return json.NewEncoder(ctx).Encode(v)
}

func init() {
encoding.RegisterDecoder(decodeJSON, "application/json")
encoding.RegisterEncoder(encodeJSON, "application/json")
encoding.RegisterDecoder(json.Unmarshal, "application/json")
encoding.RegisterEncoder(json.Marshal, "application/json")
}
2 changes: 1 addition & 1 deletion encoding/json/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type item struct {

var opt = test.EncodingOptions[item]{
Mime: "application/json",
Raw: `{"foo":"bar"}` + "\n",
Raw: `{"foo":"bar"}`,
Parsed: item{Foo: "bar"},
}

Expand Down
13 changes: 2 additions & 11 deletions encoding/msgpack/msgpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,10 @@ package msgpack

import (
"github.com/abemedia/go-don/encoding"
"github.com/valyala/fasthttp"
"github.com/vmihailenco/msgpack/v5"
)

func decodeMsgpack(ctx *fasthttp.RequestCtx, v any) error {
return msgpack.NewDecoder(ctx.RequestBodyStream()).Decode(v)
}

func encodeMsgpack(ctx *fasthttp.RequestCtx, v any) error {
return msgpack.NewEncoder(ctx).Encode(v)
}

func init() {
encoding.RegisterDecoder(decodeMsgpack, "application/x-msgpack")
encoding.RegisterEncoder(encodeMsgpack, "application/x-msgpack")
encoding.RegisterDecoder(msgpack.Unmarshal, "application/x-msgpack")
encoding.RegisterEncoder(msgpack.Marshal, "application/x-msgpack")
}
2 changes: 1 addition & 1 deletion handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestHandlerResponse(t *testing.T) {
message: "should return null",
want: response{
Code: fasthttp.StatusOK,
Body: "null\n",
Body: "null",
Header: map[string]string{
"Content-Length": "0",
"Content-Type": "application/json; charset=utf-8",
Expand Down