From 80b5a6680e2fc4d2f1e425ff2e5f1cfbbd529d9e Mon Sep 17 00:00:00 2001 From: Grégoire Duchêne Date: Sun, 4 Jul 2021 15:33:18 +0100 Subject: Simplify project structure --- resp.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 resp.go (limited to 'resp.go') 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 +// +// 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(` + +go-import-redirect +`, 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] +} -- cgit v1.2.3-70-g09d2