Skip to content

Commit c3c9aed

Browse files
committed
update option context
1 parent 8d8e360 commit c3c9aed

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

internal/genapi/opts_tmpl.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ import (
1515
"errors"
1616
"io/ioutil"
1717
"encoding/json"
18+
"context"
1819
)
1920
2021
type Option func(*Options)
2122
22-
type FnRequest func(*http.Client,*http.Request) (*http.Response, error)
23-
type FnResponse func(*http.Response, interface{}) error
23+
type FnRequest func(context.Context, *http.Client,*http.Request) (*http.Response, error)
24+
type FnResponse func(context.Context, *http.Response, interface{}) error
2425
2526
var (
2627
ErrNil = errors.New("resp nil")
@@ -58,11 +59,11 @@ func buildOptions(opt *Options, opts ...Option) *Options {
5859
return res
5960
}
6061
61-
func doRequest(client *http.Client, req *http.Request) (*http.Response, error) {
62+
func doRequest(_ context.Context, client *http.Client, req *http.Request) (*http.Response, error) {
6263
return client.Do(req)
6364
}
6465
65-
func doResponse(resp *http.Response, a interface{}) error {
66+
func doResponse(_ context.Context, resp *http.Response, a interface{}) error {
6667
if resp == nil {
6768
return ErrNil
6869
}

internal/genapi/tmpl.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ var requestCode = `// options
8585
for k, v := range headers {
8686
req.Header.Set(k, v)
8787
}
88-
resp, err := opt.DoRequest(opt.client, req)
88+
resp, err := opt.DoRequest(ctx, opt.client, req)
8989
if err != nil {
9090
return nil, err
9191
}
92-
err = opt.DoResponse(resp, &res)
92+
err = opt.DoResponse(ctx, resp, &res)
9393
return &res, err
9494
`
9595

0 commit comments

Comments
 (0)