aboutsummaryrefslogtreecommitdiff
path: root/resp.go
diff options
context:
space:
mode:
Diffstat (limited to 'resp.go')
-rw-r--r--resp.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/resp.go b/resp.go
new file mode 100644
index 0000000..3403e17
--- /dev/null
+++ b/resp.go
@@ -0,0 +1,27 @@
+// 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 main
+
+import (
+ "fmt"
+ "os"
+ "strings"
+)
+
+func GetBody(pkg string) string {
+ 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 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]
+}