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)
| 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 |
| 20 | func 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 | } |