diff options
| author | Grégoire Duchêne <gduchene@awhk.org> | 2019-09-09 21:18:59 +0100 |
|---|---|---|
| committer | Grégoire Duchêne <gduchene@awhk.org> | 2019-09-09 21:55:09 +0100 |
| commit | 0c050372cc95f231f68164ff2d8164d085ea3ccc (patch) | |
| tree | c4c6e338896516a8a3c18e7a2682dd1f80a3dbc1 /lib | |
| parent | fc1a6692348673e9703b09ae22e7cdd93c67e4ff (diff) | |
Add a version for GCP Cloud Run
Diffstat (limited to 'lib')
| -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] +} |
