diff options
| author | Grégoire Duchêne <gduchene@awhk.org> | 2020-03-26 22:00:40 +0000 |
|---|---|---|
| committer | Grégoire Duchêne <gduchene@awhk.org> | 2020-03-26 22:00:40 +0000 |
| commit | 3216dc9b8d876f24ed561e81c2a1fb91926cb57a (patch) | |
| tree | 9abb98e1741494d4856553335761904f5466baa0 /lib/lib.go | |
| parent | 0d32b71317472ab5d93aa98f8db02609ed1318bc (diff) | |
Add a few test cases to lib
Diffstat (limited to 'lib/lib.go')
| -rw-r--r-- | lib/lib.go | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -12,15 +12,16 @@ import ( ) func GetBody(pkg string) string { - dest := strings.TrimRight(os.Getenv("DEST"), "/") + "/" + getRepo(pkg) + dest := GetDest(os.Getenv("PREFIX"), os.Getenv("DEST"), pkg) return fmt.Sprintf(`<!doctype html> <meta name="go-import" content="%s %s %s"> <title>go-import-redirect</title> `, pkg, os.Getenv("VCS"), dest) } -func getRepo(pkg string) string { - prefix := strings.TrimRight(os.Getenv("PREFIX"), "/") - path := strings.TrimLeft(strings.TrimPrefix(pkg, prefix), "/") - return strings.Split(path, "/")[0] +func GetDest(srcPrefix, destPrefix, pkg string) string { + srcPrefix = strings.TrimRight(srcPrefix, "/") + destPrefix = strings.TrimRight(destPrefix, "/") + path := strings.TrimLeft(strings.TrimPrefix(pkg, srcPrefix), "/") + return destPrefix + "/" + strings.Split(path, "/")[0] } |
