@@ -22,11 +22,16 @@ func Get(
22
22
url , address string ,
23
23
timeout time.Duration ,
24
24
headers , queryParams map [string ]string ,
25
- logging bool ,
25
+ opts ... Option ,
26
26
) (int , string , error ) {
27
- resp , err := makeRequest (http .MethodGet , url , address , nil , timeout , headers , queryParams , logging )
27
+ options := & Options {logEnabled : true }
28
+ for _ , opt := range opts {
29
+ opt (options )
30
+ }
31
+
32
+ resp , err := makeRequest (http .MethodGet , url , address , nil , timeout , headers , queryParams , opts ... )
28
33
if err != nil {
29
- if logging {
34
+ if options . logEnabled {
30
35
GinkgoWriter .Printf (
31
36
"ERROR occurred during getting response, error: %s\n Returning status: 0, body: ''\n " ,
32
37
err ,
@@ -43,7 +48,7 @@ func Get(
43
48
GinkgoWriter .Printf ("ERROR in Body content: %v returning body: ''\n " , err )
44
49
return resp .StatusCode , "" , err
45
50
}
46
- if logging {
51
+ if options . logEnabled {
47
52
GinkgoWriter .Printf ("Successfully received response and parsed body: %s\n " , body .String ())
48
53
}
49
54
@@ -58,7 +63,7 @@ func Post(
58
63
timeout time.Duration ,
59
64
headers , queryParams map [string ]string ,
60
65
) (* http.Response , error ) {
61
- response , err := makeRequest (http .MethodPost , url , address , body , timeout , headers , queryParams , true )
66
+ response , err := makeRequest (http .MethodPost , url , address , body , timeout , headers , queryParams )
62
67
if err != nil {
63
68
GinkgoWriter .Printf ("ERROR occurred during getting response, error: %s\n " , err )
64
69
}
@@ -71,7 +76,7 @@ func makeRequest(
71
76
body io.Reader ,
72
77
timeout time.Duration ,
73
78
headers , queryParams map [string ]string ,
74
- logging bool ,
79
+ opts ... Option ,
75
80
) (* http.Response , error ) {
76
81
dialer := & net.Dialer {}
77
82
@@ -94,7 +99,12 @@ func makeRequest(
94
99
ctx , cancel := context .WithTimeout (context .Background (), timeout )
95
100
defer cancel ()
96
101
97
- if logging {
102
+ options := & Options {logEnabled : true }
103
+
104
+ for _ , opt := range opts {
105
+ opt (options )
106
+ }
107
+ if options .logEnabled {
98
108
requestDetails := fmt .Sprintf (
99
109
"Method: %s, URL: %s, Address: %s, Headers: %v, QueryParams: %v\n " ,
100
110
strings .ToUpper (method ),
0 commit comments