@@ -7,16 +7,16 @@ import (
77 "errors"
88 "fmt"
99 "io"
10+ "log/slog"
1011 "net/http"
1112 "net/url"
1213 "time"
13-
14- log "github.com/sirupsen/logrus"
1514)
1615
1716type RestAPI struct {
1817 URL string
1918 Client * http.Client
19+ Logger * slog.Logger
2020}
2121
2222func (a RestAPI ) ExecuteCheck (command string , arguments map [string ]interface {}, timeout uint32 ) (* APICheckResult , error ) { //nolint:lll
@@ -31,14 +31,11 @@ func (a RestAPI) ExecuteCheck(command string, arguments map[string]interface{},
3131 defer cancel ()
3232
3333 // Build request
34- requestUrl := a .URL + "/v1/checker?command=" + url .QueryEscape (command )
34+ requestURL := a .URL + "/v1/checker?command=" + url .QueryEscape (command )
3535
36- log .WithFields (log.Fields {
37- "body" : string (body ),
38- "url" : requestUrl ,
39- }).Debug ("sending request" )
36+ a .Logger .Debug ("sending request" , "body" , string (body ), "url" , requestURL )
4037
41- req , err := http .NewRequestWithContext (ctx , "POST" , requestUrl , bytes .NewReader (body ))
38+ req , err := http .NewRequestWithContext (ctx , http . MethodPost , requestURL , bytes .NewReader (body ))
4239 if err != nil {
4340 return nil , fmt .Errorf ("could not build request: %w" , err )
4441 }
@@ -53,6 +50,7 @@ func (a RestAPI) ExecuteCheck(command string, arguments map[string]interface{},
5350 if errors .Is (err , context .DeadlineExceeded ) {
5451 return nil , fmt .Errorf ("timeout during HTTP request: %w" , err )
5552 }
53+
5654 return nil , fmt .Errorf ("executing API request failed: %w" , err )
5755 }
5856
@@ -64,9 +62,9 @@ func (a RestAPI) ExecuteCheck(command string, arguments map[string]interface{},
6462 return nil , fmt .Errorf ("could not read result: %w" , err )
6563 }
6664
67- log . WithField ( " body" , string (resultBody )). Debug ( "received response" )
65+ a . Logger . Debug ( "received response" , " body" , string (resultBody ))
6866
69- if resp .StatusCode != 200 {
67+ if resp .StatusCode != http . StatusOK {
7068 return nil , fmt .Errorf ("API request not successful code=%d: %s" , resp .StatusCode , string (resultBody ))
7169 }
7270
0 commit comments