diff options
Diffstat (limited to 'lib/lib.go')
| -rw-r--r-- | lib/lib.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/lib.go b/lib/lib.go new file mode 100644 index 0000000..b066e69 --- /dev/null +++ b/lib/lib.go @@ -0,0 +1,26 @@ +// Copyright (c) 2019, GrĂ©goire DuchĂȘne <gduchene@awhk.org> +// +// Use of this source code is governed by the ISC license that can be +// found in the LICENSE file. + +package lib + +import ( + "fmt" + "os" + "strings" +) + +func GetBody(pkg string) string { + dest := strings.TrimRight(os.Getenv("DEST"), "/") + "/" + getRepo(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] +} |
