Skip to content

Commit

Permalink
fixed: http response body
Browse files Browse the repository at this point in the history
  • Loading branch information
kainonly committed Sep 16, 2023
1 parent 345da66 commit 6864244
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@
!.vscode/launch.json
!.vscode/extensions.json

vendor

config
33 changes: 14 additions & 19 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,21 @@ func (x *App) HTTPMode(job common.Job) (err error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()

var r M
var resp *req.Response
resp, err = x.Http.R().
if resp, err = x.Http.R().
SetContext(ctx).
SetHeaders(option.Headers).
SetBody(option.Body).
SetSuccessResult(&r).
SetErrorResult(&r).
Post(option.Url)
Post(option.Url); err != nil {
x.Log.Error("Http:fail",
zap.String("key", job.Key),
zap.Int("index", job.Index),
zap.Any("headers", option.Headers),
zap.Any("body", option.Body),
zap.Error(err),
)
return
}

now := time.Now()
if e := x.Transfer.Publish(ctx, "logset_jobs", transfer.Payload{
Expand All @@ -94,7 +100,7 @@ func (x *App) HTTPMode(job common.Job) (err error) {
"body": option.Body,
"response": M{
"status": resp.StatusCode,
"body": r,
"body": string(resp.Bytes()),
},
},
XData: M{},
Expand All @@ -104,19 +110,8 @@ func (x *App) HTTPMode(job common.Job) (err error) {
zap.Int("index", job.Index),
zap.Any("headers", option.Headers),
zap.Any("body", option.Body),
zap.Error(err),
)
return
}
if err != nil {
x.Log.Error("Http:fail",
zap.String("key", job.Key),
zap.Int("index", job.Index),
zap.Any("headers", option.Headers),
zap.Any("body", option.Body),
zap.Error(err),
zap.Error(e),
)
// TODO: Event Callback
return
}
x.Log.Debug("Http:ok",
Expand All @@ -126,7 +121,7 @@ func (x *App) HTTPMode(job common.Job) (err error) {
zap.Any("body", option.Body),
zap.Any("response", M{
"status": resp.StatusCode,
"body": r,
"body": string(resp.Bytes()),
}),
)
return
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/bytedance/sonic v1.10.1
github.com/caarlos0/env/v9 v9.0.0
github.com/google/wire v0.5.0
github.com/imroc/req/v3 v3.41.12
github.com/imroc/req/v3 v3.42.0
github.com/mitchellh/mapstructure v1.5.0
github.com/nats-io/nats.go v1.29.0
github.com/nats-io/nkeys v0.4.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/imroc/req/v3 v3.41.12 h1:OyPoCpVr8lpWuBwaEnqshA2xYLoxKPnjRIRVaZ+/NoQ=
github.com/imroc/req/v3 v3.41.12/go.mod h1:W7dOrfQORA9nFoj+CafIZ6P5iyk+rWdbp2sffOAvABU=
github.com/imroc/req/v3 v3.42.0 h1:g7wWva3aIJI02mrnqmXe0N5SVkXHQPsYN3Tmw2ZHn3U=
github.com/imroc/req/v3 v3.42.0/go.mod h1:W7dOrfQORA9nFoj+CafIZ6P5iyk+rWdbp2sffOAvABU=
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I=
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
Expand Down

0 comments on commit 6864244

Please sign in to comment.