Add context timeouts for third-party requests
Some checks failed
/ golint (push) Failing after 3m56s
Some checks failed
/ golint (push) Failing after 3m56s
Avoid hanging a goroutine for a long time.
This commit is contained in:
parent
2093ea74c4
commit
15d8966971
11 changed files with 80 additions and 5 deletions
|
|
@ -35,10 +35,13 @@ type OAuthTokenResponse struct {
|
|||
}
|
||||
|
||||
func DoTokenRequest(ctx context.Context, form url.Values) (*OAuthTokenResponse, error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, 15*time.Second)
|
||||
defer cancel()
|
||||
|
||||
form.Set("client_id", config.ClientID)
|
||||
|
||||
baseURL := "https://www.arcgis.com/sharing/rest/oauth2/token/"
|
||||
req, err := http.NewRequest("POST", baseURL, strings.NewReader(form.Encode()))
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", baseURL, strings.NewReader(form.Encode()))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to create request: %w", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue