9 // GCSDetector implements Detector to detect GCS URLs and turn
10 // them into URLs that the GCSGetter can understand.
11 type GCSDetector struct{}
13 func (d *GCSDetector) Detect(src, _ string) (string, bool, error) {
18 if strings.Contains(src, "googleapis.com/") {
19 return d.detectHTTP(src)
25 func (d *GCSDetector) detectHTTP(src string) (string, bool, error) {
27 parts := strings.Split(src, "/")
29 return "", false, fmt.Errorf(
30 "URL is not a valid GCS URL")
34 object := strings.Join(parts[4:], "/")
36 url, err := url.Parse(fmt.Sprintf("https://www.googleapis.com/storage/%s/%s/%s",
37 version, bucket, object))
39 return "", false, fmt.Errorf("error parsing GCS URL: %s", err)
42 return "gcs::" + url.String(), true, nil