Add Gogs helpers

git-svn-id: file:///srv/svn/repo/toyohime/trunk@77 922d331f-388e-da47-97a9-ad700dc0b8b9
This commit is contained in:
jonbetti 2018-06-05 02:40:45 +00:00
parent c5862e5226
commit 44a5244794

View File

@ -85,6 +85,13 @@ func GitHubStyleSourceTag(importPath, repoPath, ref string) tag {
return SourceTag(importPath, repoPath, directory, file)
}
func GogsStyleSourceTag(importPath, repoPath, ref string) tag {
directory := repoPath + "/src/" + ref + "{/dir}"
file := repoPath + "/src/" + ref + "{/dir}/{file}#L{line}"
return SourceTag(importPath, repoPath, directory, file)
}
// Creates a Handler that serves a GitHub repository at a specific importPath.
func GitHubHandler(importPath, user, repo, vcsScheme string) http.Handler {
ghImportPath := "github.com/" + user + "/" + repo
@ -93,3 +100,13 @@ func GitHubHandler(importPath, user, repo, vcsScheme string) http.Handler {
GitHubStyleSourceTag(importPath, "https://"+ghImportPath, "master"),
)
}
// Creates a Handler that serves a repository hosted with Gogs at host at a
// specific importPath.
func GogsHandler(importPath, host, user, repo, vcsScheme string) http.Handler {
gogsImportPath := host + "/" + user + "/" + repo
return Handler(
ImportTag(importPath, "git", vcsScheme+"://"+gogsImportPath),
GogsStyleSourceTag(importPath, "https://"+gogsImportPath, "master"),
)
}