MCPcopy
hub / github.com/hashicorp/go-getter / Detect

Function Detect

detect.go:20–59  ·  view source on GitHub ↗

Detect is a method used to detect if a Getter is a candidate for downloading an artifact by calling the Getter.Detect(*Request) method

(req *Request, getter Getter)

Source from the content-addressed store, hash-verified

18// Detect is a method used to detect if a Getter is a candidate for downloading an artifact
19// by calling the Getter.Detect(*Request) method
20func Detect(req *Request, getter Getter) (bool, error) {
21 originalSrc := req.Src
22
23 getForce, getSrc := getForcedGetter(req.Src)
24 if getForce != "" {
25 req.Forced = getForce
26 }
27
28 req.Src = getSrc
29 ok, err := getter.Detect(req)
30 if err != nil {
31 return true, err
32 }
33 if !ok {
34 // Write back the original source
35 req.Src = originalSrc
36 return ok, nil
37 }
38
39 result, detectSubdir := SourceDirSubdir(req.Src)
40
41 // If we have a subdir from the detection, then prepend it to our
42 // requested subdir.
43 if detectSubdir != "" {
44 u, err := url.Parse(result)
45 if err != nil {
46 return true, fmt.Errorf("Error parsing URL: %s", err)
47 }
48 u.Path += "//" + detectSubdir
49
50 // a subdir may contain wildcards, but in order to support them we
51 // have to ensure the path isn't escaped.
52 u.RawPath = u.Path
53
54 result = u.String()
55 }
56
57 req.Src = result
58 return true, nil
59}

Callers 5

TestGitGetter_DetectorFunction · 0.85
TestDetectFunction · 0.85
GetMethod · 0.85
getXTerraformSourceMethod · 0.85

Calls 5

ParseFunction · 0.92
getForcedGetterFunction · 0.85
SourceDirSubdirFunction · 0.85
DetectMethod · 0.65
StringMethod · 0.45

Tested by 3

TestGitGetter_DetectorFunction · 0.68
TestDetectFunction · 0.68