Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(getter): race condition when SetClient is called #466

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (c *Client) Configure(opts ...ClientOption) error {
c.Detectors = Detectors
}
if c.Getters == nil {
c.Getters = Getters
c.Getters = DefaultGetters()
}

// Set the client for each getter, so the top-level client can know
Expand Down
11 changes: 9 additions & 2 deletions get.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ var forcedRegexp = regexp.MustCompile(`^([A-Za-z0-9]+)::(.+)$`)
// httpClient is the default client to be used by HttpGetters.
var httpClient = cleanhttp.DefaultClient()

func init() {
// DefaultGetters returns the default set of getters. This is used by the
// Client if no Getters are specified. It returns a new independent map.
func DefaultGetters() map[string]Getter {
httpGetter := &HttpGetter{
Netrc: true,
}

Getters = map[string]Getter{
getters := map[string]Getter{
"file": new(FileGetter),
"git": new(GitGetter),
"gcs": new(GCSGetter),
Expand All @@ -73,6 +75,11 @@ func init() {
"http": httpGetter,
"https": httpGetter,
}
return getters
}

func init() {
Getters = DefaultGetters()
}

// Get downloads the directory specified by src into the folder specified by
Expand Down