refactor: use http.NewRequestWithContext instead of http.NewRequest (#97)
This commit is contained in:
6
image.go
6
image.go
@@ -53,12 +53,11 @@ func (c *Client) CreateImage(ctx context.Context, request ImageRequest) (respons
|
||||
}
|
||||
|
||||
urlSuffix := "/images/generations"
|
||||
req, err := http.NewRequest(http.MethodPost, c.fullURL(urlSuffix), bytes.NewBuffer(reqBytes))
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.fullURL(urlSuffix), bytes.NewBuffer(reqBytes))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
req = req.WithContext(ctx)
|
||||
err = c.sendRequest(req, &response)
|
||||
return
|
||||
}
|
||||
@@ -111,12 +110,11 @@ func (c *Client) CreateEditImage(ctx context.Context, request ImageEditRequest)
|
||||
}
|
||||
writer.Close()
|
||||
urlSuffix := "/images/edits"
|
||||
req, err := http.NewRequest(http.MethodPost, c.fullURL(urlSuffix), body)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.fullURL(urlSuffix), body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
req = req.WithContext(ctx)
|
||||
req.Header.Set("Content-Type", writer.FormDataContentType())
|
||||
err = c.sendRequest(req, &response)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user