@@ -98,12 +98,11 @@ func (c *Client) CreateFile(ctx context.Context, request FileRequest) (file File
98
98
99
99
w .Close ()
100
100
101
- req , err := http .NewRequest ( "POST" , c .fullURL ("/files" ), & b )
101
+ req , err := http .NewRequestWithContext ( ctx , http . MethodPost , c .fullURL ("/files" ), & b )
102
102
if err != nil {
103
103
return
104
104
}
105
105
106
- req = req .WithContext (ctx )
107
106
req .Header .Set ("Content-Type" , w .FormDataContentType ())
108
107
109
108
err = c .sendRequest (req , & file )
@@ -113,25 +112,23 @@ func (c *Client) CreateFile(ctx context.Context, request FileRequest) (file File
113
112
114
113
// DeleteFile deletes an existing file.
115
114
func (c * Client ) DeleteFile (ctx context.Context , fileID string ) (err error ) {
116
- req , err := http .NewRequest ( "DELETE" , c .fullURL ("/files/" + fileID ), nil )
115
+ req , err := http .NewRequestWithContext ( ctx , http . MethodDelete , c .fullURL ("/files/" + fileID ), nil )
117
116
if err != nil {
118
117
return
119
118
}
120
119
121
- req = req .WithContext (ctx )
122
120
err = c .sendRequest (req , nil )
123
121
return
124
122
}
125
123
126
124
// ListFiles Lists the currently available files,
127
125
// and provides basic information about each file such as the file name and purpose.
128
126
func (c * Client ) ListFiles (ctx context.Context ) (files FilesList , err error ) {
129
- req , err := http .NewRequest ( "GET" , c .fullURL ("/files" ), nil )
127
+ req , err := http .NewRequestWithContext ( ctx , http . MethodGet , c .fullURL ("/files" ), nil )
130
128
if err != nil {
131
129
return
132
130
}
133
131
134
- req = req .WithContext (ctx )
135
132
err = c .sendRequest (req , & files )
136
133
return
137
134
}
@@ -140,12 +137,11 @@ func (c *Client) ListFiles(ctx context.Context) (files FilesList, err error) {
140
137
// such as the file name and purpose.
141
138
func (c * Client ) GetFile (ctx context.Context , fileID string ) (file File , err error ) {
142
139
urlSuffix := fmt .Sprintf ("/files/%s" , fileID )
143
- req , err := http .NewRequest ( "GET" , c .fullURL (urlSuffix ), nil )
140
+ req , err := http .NewRequestWithContext ( ctx , http . MethodGet , c .fullURL (urlSuffix ), nil )
144
141
if err != nil {
145
142
return
146
143
}
147
144
148
- req = req .WithContext (ctx )
149
145
err = c .sendRequest (req , & file )
150
146
return
151
147
}
0 commit comments