aboutsummaryrefslogtreecommitdiff
path: root/resp.go
blob: f90c486a4b5c4f270d2d31e74d3ecfbdcc5e49e6 (plain)
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
// SPDX-FileCopyrightText: © 2019 Grégoire Duchêne <gduchene@awhk.org>
// SPDX-License-Identifier: ISC

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]
}