Skip to content

Commit

Permalink
Add a 3 second timeout to SAM Local version upgrade checks
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulMaddox committed Aug 8, 2017
1 parent b946a6f commit 7f16c7a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ package main
import (
"context"
"log"
"net/http"
"time"

"github.com/google/go-github/github"
)

// githubTimeout defines how long to wait for a response from GitHub
// when checking for new SAM Local versions.
const githubTimeout = 3

// checkVersionResult contains information on the current version of AWS SAM CLI, and
// whether there are any newer versions available to upgrade to.
type checkVersionResult struct {
Expand All @@ -20,8 +26,13 @@ func checkVersion() (*checkVersionResult, error) {
const RepoOwner = "awslabs"
const RepoName = "aws-sam-local"

// Create a HTTP client with appropriate timeouts configured
client := &http.Client{
Timeout: time.Duration(githubTimeout * time.Second),
}

// Get the latest version details from Github release
gh := github.NewClient(nil)
gh := github.NewClient(client)
releases, _, err := gh.Repositories.ListReleases(context.Background(), RepoOwner, RepoName, nil)
if err != nil {
return &checkVersionResult{}, err
Expand Down

0 comments on commit 7f16c7a

Please sign in to comment.