diff options
Diffstat (limited to 'vendor/github.com/hashicorp/go-getter/source.go')
-rw-r--r-- | vendor/github.com/hashicorp/go-getter/source.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/go-getter/source.go b/vendor/github.com/hashicorp/go-getter/source.go new file mode 100644 index 0000000..4d5ee3c --- /dev/null +++ b/vendor/github.com/hashicorp/go-getter/source.go | |||
@@ -0,0 +1,36 @@ | |||
1 | package getter | ||
2 | |||
3 | import ( | ||
4 | "strings" | ||
5 | ) | ||
6 | |||
7 | // SourceDirSubdir takes a source and returns a tuple of the URL without | ||
8 | // the subdir and the URL with the subdir. | ||
9 | func SourceDirSubdir(src string) (string, string) { | ||
10 | // Calcaulate an offset to avoid accidentally marking the scheme | ||
11 | // as the dir. | ||
12 | var offset int | ||
13 | if idx := strings.Index(src, "://"); idx > -1 { | ||
14 | offset = idx + 3 | ||
15 | } | ||
16 | |||
17 | // First see if we even have an explicit subdir | ||
18 | idx := strings.Index(src[offset:], "//") | ||
19 | if idx == -1 { | ||
20 | return src, "" | ||
21 | } | ||
22 | |||
23 | idx += offset | ||
24 | subdir := src[idx+2:] | ||
25 | src = src[:idx] | ||
26 | |||
27 | // Next, check if we have query parameters and push them onto the | ||
28 | // URL. | ||
29 | if idx = strings.Index(subdir, "?"); idx > -1 { | ||
30 | query := subdir[idx:] | ||
31 | subdir = subdir[:idx] | ||
32 | src += query | ||
33 | } | ||
34 | |||
35 | return src, subdir | ||
36 | } | ||