Skip to content

Commit

Permalink
fix: remove not need mime type
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkgos committed Apr 26, 2024
1 parent 3988bf8 commit b327149
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
28 changes: 18 additions & 10 deletions encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ import (
"github.com/things-go/encoding/codec"
"github.com/things-go/encoding/form"
"github.com/things-go/encoding/jsonpb"
"github.com/things-go/encoding/msgpack"
"github.com/things-go/encoding/proto"
"github.com/things-go/encoding/toml"
"github.com/things-go/encoding/xml"
"github.com/things-go/encoding/yaml"
)

const defaultMemory = 32 << 20
Expand Down Expand Up @@ -60,6 +56,24 @@ type Encoding struct {
}

// New encoding with default Marshalers
// Default:
//
// MIMEPOSTForm: form.Codec
// MIMEMultipartPOSTForm: form.MultipartCodec
// MIMEJSON: jsonpb.Codec
// MIMEPROTOBUF: proto.Codec
// mimeQuery: form.QueryCodec
// mimeUri: form.UriCodec
// mimeWildcard: HTTPBodyCodec
//
// you can manually register your custom Marshaler.
//
// MIMEXML: xml.Codec
// MIMEXML2: xml.Codec
// MIMEMSGPACK: msgpack.Codec
// MIMEMSGPACK2: msgpack.Codec
// MIMEYAML: yaml.Codec
// SMIMETOML: toml.Codec
func New() *Encoding {
return &Encoding{
mimeMap: map[string]codec.Marshaler{
Expand All @@ -74,13 +88,7 @@ func New() *Encoding {
DiscardUnknown: true,
},
},
MIMEXML: &xml.Codec{},
MIMEXML2: &xml.Codec{},
MIMEPROTOBUF: &proto.Codec{},
MIMEMSGPACK: &msgpack.Codec{},
MIMEMSGPACK2: &msgpack.Codec{},
MIMEYAML: &yaml.Codec{},
MIMETOML: &toml.Codec{},
},
mimeQuery: &form.QueryCodec{Codec: form.New("json")},
mimeUri: &form.UriCodec{Codec: form.New("json")},
Expand Down
9 changes: 9 additions & 0 deletions encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import (
"github.com/things-go/encoding/json"
"github.com/things-go/encoding/msgpack"
"github.com/things-go/encoding/testdata/examplepb"
"github.com/things-go/encoding/toml"
"github.com/things-go/encoding/xml"
"github.com/things-go/encoding/yaml"
)

var marshalers = []dummyMarshaler{0, 1}
Expand Down Expand Up @@ -211,6 +214,12 @@ var protoMessage = &examplepb.ABitOfEverything{

func Test_Encoding_Bind(t *testing.T) {
registry := New()
_ = registry.Register(MIMEXML, &xml.Codec{})
_ = registry.Register(MIMEXML2, &xml.Codec{})
_ = registry.Register(MIMEMSGPACK, &msgpack.Codec{})
_ = registry.Register(MIMEMSGPACK2, &msgpack.Codec{})
_ = registry.Register(MIMEYAML, &yaml.Codec{})
_ = registry.Register(MIMETOML, &toml.Codec{})
tests := []struct {
name string
genReq func() (*http.Request, error)
Expand Down

0 comments on commit b327149

Please sign in to comment.