Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
lixizan committed Nov 10, 2023
1 parent e2a3bf1 commit 452dc1b
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 9 deletions.
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (c *Client) Request(method string, url string, args ...any) *Request {
headers: http.Header{},
}

r.SetEncoder(c.config.Encoder)
r.SetEncoder(JsonEncoder)

return r
}
1 change: 1 addition & 0 deletions codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func FormDecode(r io.Reader, v any) error {
var buffer = internal.GetBuffer()
var p = buffer.Bytes()[:internal.BufferSize]
_, _ = io.CopyBuffer(builder, r, p)
internal.PutBuffer(buffer)
result, err := url.ParseQuery(builder.String())
if err != nil {
return errors.WithStack(err)
Expand Down
5 changes: 0 additions & 5 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ type (
BeforeFunc BeforeFunc // 请求前中间件
AfterFunc AfterFunc // 请求后中间件
HTTPClient *http.Client // HTTP客户端
Encoder Encoder // 编码器
}

Option func(c *config)
Expand Down Expand Up @@ -90,10 +89,6 @@ func withInitialize() Option {
c.AfterFunc = defaultAfterFunc
}

if c.Encoder == nil {
c.Encoder = JsonEncoder
}

if c.HTTPClient == nil {
c.HTTPClient = &http.Client{
Timeout: defaultTimeout,
Expand Down
4 changes: 1 addition & 3 deletions contrib/yaml/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,5 @@ func (c encoder) ContentType() string {
}

func Decode(r io.Reader, v any) error {
return errors.WithStack(
yaml.NewDecoder(r).Decode(v),
)
return errors.WithStack(yaml.NewDecoder(r).Decode(v))
}

0 comments on commit 452dc1b

Please sign in to comment.