Skip to content

Commit c42f3e8

Browse files
committed
refactored the functions to be aligned with the older way of doing things
1 parent 1f1894b commit c42f3e8

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

client/nginx.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -927,13 +927,13 @@ func (client *NginxClient) getIDOfHTTPServer(upstream string, name string) (int,
927927
}
928928

929929
func (client *NginxClient) get(path string, data interface{}) error {
930-
return client.getWithContext(context.Background(), path, data)
930+
timeoutCtx, cancel := context.WithTimeout(context.Background(), client.ctxTimeout)
931+
defer cancel()
932+
933+
return client.getWithContext(timeoutCtx, path, data)
931934
}
932935

933936
func (client *NginxClient) getWithContext(ctx context.Context, path string, data interface{}) error {
934-
ctx, cancel := context.WithTimeout(ctx, client.ctxTimeout)
935-
defer cancel()
936-
937937
url := fmt.Sprintf("%v/%v/%v", client.apiEndpoint, client.apiVersion, path)
938938

939939
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
@@ -965,13 +965,13 @@ func (client *NginxClient) getWithContext(ctx context.Context, path string, data
965965
}
966966

967967
func (client *NginxClient) post(path string, input interface{}) error {
968-
return client.postWithContext(context.Background(), path, input)
968+
timeoutCtx, cancel := context.WithTimeout(context.Background(), client.ctxTimeout)
969+
defer cancel()
970+
971+
return client.postWithContext(timeoutCtx, path, input)
969972
}
970973

971974
func (client *NginxClient) postWithContext(ctx context.Context, path string, input interface{}) error {
972-
ctx, cancel := context.WithTimeout(ctx, client.ctxTimeout)
973-
defer cancel()
974-
975975
url := fmt.Sprintf("%v/%v/%v", client.apiEndpoint, client.apiVersion, path)
976976

977977
jsonInput, err := json.Marshal(input)
@@ -1001,13 +1001,13 @@ func (client *NginxClient) postWithContext(ctx context.Context, path string, inp
10011001
}
10021002

10031003
func (client *NginxClient) delete(path string, expectedStatusCode int) error {
1004-
return client.deleteWithContext(context.Background(), path, expectedStatusCode)
1004+
timeoutCtx, cancel := context.WithTimeout(context.Background(), client.ctxTimeout)
1005+
defer cancel()
1006+
1007+
return client.deleteWithContext(timeoutCtx, path, expectedStatusCode)
10051008
}
10061009

10071010
func (client *NginxClient) deleteWithContext(ctx context.Context, path string, expectedStatusCode int) error {
1008-
ctx, cancel := context.WithTimeout(ctx, client.ctxTimeout)
1009-
defer cancel()
1010-
10111011
path = fmt.Sprintf("%v/%v/%v/", client.apiEndpoint, client.apiVersion, path)
10121012

10131013
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, path, nil)
@@ -1030,13 +1030,13 @@ func (client *NginxClient) deleteWithContext(ctx context.Context, path string, e
10301030
}
10311031

10321032
func (client *NginxClient) patch(path string, input interface{}, expectedStatusCode int) error {
1033-
return client.patchWithContext(context.Background(), path, input, expectedStatusCode)
1033+
timeoutCtx, cancel := context.WithTimeout(context.Background(), client.ctxTimeout)
1034+
defer cancel()
1035+
1036+
return client.patchWithContext(timeoutCtx, path, input, expectedStatusCode)
10341037
}
10351038

10361039
func (client *NginxClient) patchWithContext(ctx context.Context, path string, input interface{}, expectedStatusCode int) error {
1037-
ctx, cancel := context.WithTimeout(ctx, client.ctxTimeout)
1038-
defer cancel()
1039-
10401040
path = fmt.Sprintf("%v/%v/%v/", client.apiEndpoint, client.apiVersion, path)
10411041

10421042
jsonInput, err := json.Marshal(input)

0 commit comments

Comments
 (0)