@@ -198,7 +198,14 @@ page:
198198func (clt APIClient ) GetSoftware (id string ) (* Software , error ) {
199199 var softwareResponse Software
200200
201- res , err := clt .retryableClient .Get (joinPath (clt .baseURL , "/software" ) + "/" + id )
201+ url := joinPath (clt .baseURL , "/software" ) + "/" + id
202+
203+ req , err := http .NewRequestWithContext (context .Background (), http .MethodGet , url , nil )
204+ if err != nil {
205+ return nil , fmt .Errorf ("can't GET /software/%s: %w" , id , err )
206+ }
207+
208+ res , err := clt .retryableClient .Do (req )
202209 if err != nil {
203210 return nil , fmt .Errorf ("can't GET /software/%s: %w" , id , err )
204211 }
@@ -219,7 +226,14 @@ func (clt APIClient) GetSoftware(id string) (*Software, error) {
219226func (clt APIClient ) GetSoftwareByURL (url string ) (* Software , error ) {
220227 var softwareResponse SoftwarePaginated
221228
222- res , err := clt .retryableClient .Get (joinPath (clt .baseURL , "/software" ) + "?url=" + url )
229+ reqURL := joinPath (clt .baseURL , "/software" ) + "?url=" + url
230+
231+ req , err := http .NewRequestWithContext (context .Background (), http .MethodGet , reqURL , nil )
232+ if err != nil {
233+ return nil , fmt .Errorf ("can't GET /software?url=%s: %w" , url , err )
234+ }
235+
236+ res , err := clt .retryableClient .Do (req )
223237 if err != nil {
224238 return nil , fmt .Errorf ("can't GET /software?url=%s: %w" , url , err )
225239 }
@@ -241,7 +255,7 @@ func (clt APIClient) GetSoftwareByURL(url string) (*Software, error) {
241255// PostSoftware creates a new software resource with the given fields and returns
242256// a Software struct or any error encountered.
243257func (clt APIClient ) PostSoftware (url string , aliases []string , publiccodeYml string , active bool ) (* Software , error ) {
244- body , err := json .Marshal (map [string ]interface {} {
258+ body , err := json .Marshal (map [string ]any {
245259 "publiccodeYml" : publiccodeYml ,
246260 "url" : url ,
247261 "aliases" : aliases ,
@@ -273,73 +287,78 @@ func (clt APIClient) PostSoftware(url string, aliases []string, publiccodeYml st
273287}
274288
275289// PatchSoftware updates a software resource with the given fields and returns
276- // an http.Response and any error encountered.
290+ // any error encountered.
277291func (clt APIClient ) PatchSoftware (
278292 id string , url string , aliases []string , publiccodeYml string ,
279- ) ( * http. Response , error ) {
280- body , err := json .Marshal (map [string ]interface {} {
293+ ) error {
294+ body , err := json .Marshal (map [string ]any {
281295 "publiccodeYml" : publiccodeYml ,
282296 "url" : url ,
283297 "aliases" : aliases ,
284298 })
285299 if err != nil {
286- return nil , fmt .Errorf ("can't update software: %w" , err )
300+ return fmt .Errorf ("can't update software: %w" , err )
287301 }
288302
289- res , err := clt .Patch (joinPath (clt .baseURL , "/software/" + id ), body ) //nolint:bodyclose
303+ res , err := clt .Patch (joinPath (clt .baseURL , "/software/" + id ), body )
290304 if err != nil {
291- return res , fmt .Errorf ("can't update software: %w" , err )
305+ return fmt .Errorf ("can't update software: %w" , err )
292306 }
293307
308+ defer res .Body .Close ()
309+
294310 if res .StatusCode < 200 || res .StatusCode > 299 {
295- return res , fmt .Errorf ("can't update software: API replied with HTTP %s" , res .Status )
311+ return fmt .Errorf ("can't update software: API replied with HTTP %s" , res .Status )
296312 }
297313
298- return res , nil
314+ return nil
299315}
300316
301317// PostSoftwareLog creates a new software log with the given fields and returns
302- // an http.Response and any error encountered.
303- func (clt APIClient ) PostSoftwareLog (softwareID string , message string ) ( * http. Response , error ) {
304- payload , err := json .Marshal (map [string ]interface {} {
318+ // any error encountered.
319+ func (clt APIClient ) PostSoftwareLog (softwareID string , message string ) error {
320+ payload , err := json .Marshal (map [string ]any {
305321 "message" : message ,
306322 })
307323 if err != nil {
308- return nil , fmt .Errorf ("can't create log: %w" , err )
324+ return fmt .Errorf ("can't create log: %w" , err )
309325 }
310326
311- res , err := clt .Post (joinPath (clt .baseURL , "/software/" , softwareID , "logs" ), payload ) //nolint:bodyclose
327+ res , err := clt .Post (joinPath (clt .baseURL , "/software/" , softwareID , "logs" ), payload )
312328 if err != nil {
313- return res , fmt .Errorf ("can't create software log: %w" , err )
329+ return fmt .Errorf ("can't create software log: %w" , err )
314330 }
315331
332+ defer res .Body .Close ()
333+
316334 if res .StatusCode < 200 || res .StatusCode > 299 {
317- return res , fmt .Errorf ("can't create software log: API replied with HTTP %s" , res .Status )
335+ return fmt .Errorf ("can't create software log: API replied with HTTP %s" , res .Status )
318336 }
319337
320- return res , nil
338+ return nil
321339}
322340
323- // PostLog creates a new log with the given message and returns an http.Response
324- // and any error encountered.
325- func (clt APIClient ) PostLog (message string ) (* http.Response , error ) {
326- payload , err := json .Marshal (map [string ]interface {}{
341+ // PostLog creates a new log with the given message and returns any error encountered.
342+ func (clt APIClient ) PostLog (message string ) error {
343+ payload , err := json .Marshal (map [string ]any {
327344 "message" : message ,
328345 })
329346 if err != nil {
330- return nil , fmt .Errorf ("can't create log: %w" , err )
347+ return fmt .Errorf ("can't create log: %w" , err )
331348 }
332349
333- res , err := clt .Post (joinPath (clt .baseURL , "/logs" ), payload ) //nolint:bodyclose
350+ res , err := clt .Post (joinPath (clt .baseURL , "/logs" ), payload )
334351 if err != nil {
335- return res , fmt .Errorf ("can't create log: %w" , err )
352+ return fmt .Errorf ("can't create log: %w" , err )
336353 }
337354
355+ defer res .Body .Close ()
356+
338357 if res .StatusCode < 200 || res .StatusCode > 299 {
339- return res , fmt .Errorf ("can't create log: API replied with HTTP %s" , res .Status )
358+ return fmt .Errorf ("can't create log: API replied with HTTP %s" , res .Status )
340359 }
341360
342- return res , nil
361+ return nil
343362}
344363
345364func joinPath (base string , paths ... string ) string {
0 commit comments