File: source.go

package info (click to toggle)
golang-github-hashicorp-go-getter 0.0~git20160316.0.575ec4e-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 904 kB
  • ctags: 238
  • sloc: sh: 286; makefile: 5
file content (36 lines) | stat: -rw-r--r-- 775 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package getter

import (
	"strings"
)

// SourceDirSubdir takes a source and returns a tuple of the URL without
// the subdir and the URL with the subdir.
func SourceDirSubdir(src string) (string, string) {
	// Calcaulate an offset to avoid accidentally marking the scheme
	// as the dir.
	var offset int
	if idx := strings.Index(src, "://"); idx > -1 {
		offset = idx + 3
	}

	// First see if we even have an explicit subdir
	idx := strings.Index(src[offset:], "//")
	if idx == -1 {
		return src, ""
	}

	idx += offset
	subdir := src[idx+2:]
	src = src[:idx]

	// Next, check if we have query parameters and push them onto the
	// URL.
	if idx = strings.Index(subdir, "?"); idx > -1 {
		query := subdir[idx:]
		subdir = subdir[:idx]
		src += query
	}

	return src, subdir
}