@@ -2,6 +2,7 @@ package client
2
2
3
3
import (
4
4
"bytes"
5
+ "context"
5
6
"encoding/json"
6
7
"errors"
7
8
"fmt"
@@ -10,6 +11,7 @@ import (
10
11
"net/http"
11
12
"reflect"
12
13
"strings"
14
+ "time"
13
15
)
14
16
15
17
const (
@@ -752,9 +754,12 @@ func (client *NginxClient) post(path string, input interface{}) error {
752
754
}
753
755
754
756
func (client * NginxClient ) delete (path string , expectedStatusCode int ) error {
757
+ ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
758
+ defer cancel ()
759
+
755
760
path = fmt .Sprintf ("%v/%v/%v/" , client .apiEndpoint , client .version , path )
756
761
757
- req , err := http .NewRequest ( http .MethodDelete , path , nil )
762
+ req , err := http .NewRequestWithContext ( ctx , http .MethodDelete , path , nil )
758
763
if err != nil {
759
764
return fmt .Errorf ("failed to create a delete request: %w" , err )
760
765
}
@@ -774,14 +779,17 @@ func (client *NginxClient) delete(path string, expectedStatusCode int) error {
774
779
}
775
780
776
781
func (client * NginxClient ) patch (path string , input interface {}, expectedStatusCode int ) error {
782
+ ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
783
+ defer cancel ()
784
+
777
785
path = fmt .Sprintf ("%v/%v/%v/" , client .apiEndpoint , client .version , path )
778
786
779
787
jsonInput , err := json .Marshal (input )
780
788
if err != nil {
781
789
return fmt .Errorf ("failed to marshall input: %w" , err )
782
790
}
783
791
784
- req , err := http .NewRequest ( http .MethodPatch , path , bytes .NewBuffer (jsonInput ))
792
+ req , err := http .NewRequestWithContext ( ctx , http .MethodPatch , path , bytes .NewBuffer (jsonInput ))
785
793
if err != nil {
786
794
return fmt .Errorf ("failed to create a patch request: %w" , err )
787
795
}
0 commit comments