2024-01-12 04:14:09 -06:00
|
|
|
package main
|
|
|
|
|
2024-12-14 10:47:08 -06:00
|
|
|
// parses /etc/gowebd/repomap
|
|
|
|
// this file defines what repositories show up on go.wit.com
|
|
|
|
|
2024-01-12 04:14:09 -06:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2024-01-31 08:45:58 -06:00
|
|
|
"os"
|
|
|
|
"strings"
|
2024-01-12 04:14:09 -06:00
|
|
|
|
2024-01-31 08:45:58 -06:00
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
2024-01-12 04:14:09 -06:00
|
|
|
|
2024-12-14 10:47:08 -06:00
|
|
|
// this makes the "go-source" / "go-import" page
|
|
|
|
// this redirects the go path "go.wit.com/apps/go-clone" to the git path "gitea.wit.com/wit/go-clone"
|
2024-01-12 15:17:55 -06:00
|
|
|
func repoHTML(w http.ResponseWriter, gourl string, realurl string) {
|
2024-01-12 11:55:45 -06:00
|
|
|
realurl = "https://" + realurl
|
|
|
|
log.Info("go repo =", gourl, "real url =", realurl)
|
2024-01-12 04:14:09 -06:00
|
|
|
fmt.Fprintln(w, "<!DOCTYPE html>")
|
|
|
|
fmt.Fprintln(w, "<html>")
|
|
|
|
fmt.Fprintln(w, "<head>")
|
2024-01-31 08:45:58 -06:00
|
|
|
// fmt.Fprintln(w,
|
|
|
|
fmt.Fprintln(w, "<meta name=\"go-import\" content=\"", gourl, "git", realurl+"\">")
|
|
|
|
fmt.Fprintln(w, "<meta name=\"go-source\" content=\"", gourl, realurl, realurl+"/tree/master{/dir}", realurl+"tree/master{/dir}/{file}#L{line}", "\"", ">")
|
2024-01-12 04:14:09 -06:00
|
|
|
|
2024-01-31 08:45:58 -06:00
|
|
|
fmt.Fprintln(w, "<meta http-equiv=\"refresh\" content=\"0; url="+realurl+"\">")
|
2024-01-12 04:14:09 -06:00
|
|
|
fmt.Fprintln(w, "</head>")
|
|
|
|
fmt.Fprintln(w, "<body>")
|
2024-01-31 08:45:58 -06:00
|
|
|
fmt.Fprintln(w, "Nothing to see here. Please <a href=\""+realurl+"\">move along</a>.\"")
|
2024-01-12 04:14:09 -06:00
|
|
|
fmt.Fprintln(w, "</body>")
|
|
|
|
fmt.Fprintln(w, "</html>")
|
|
|
|
}
|
2024-01-12 04:44:36 -06:00
|
|
|
|
2024-01-12 11:13:26 -06:00
|
|
|
func findkey(url string) (string, string) {
|
|
|
|
key := "go.wit.com" + url
|
|
|
|
if repoMap[key] != "" {
|
|
|
|
return key, repoMap[key]
|
|
|
|
}
|
|
|
|
return key, ""
|
|
|
|
// parts := strings.Split(key, "/")
|
|
|
|
}
|
|
|
|
|
2024-12-14 10:47:08 -06:00
|
|
|
func readRepomap() {
|
2024-10-08 11:36:46 -05:00
|
|
|
var pfile []byte
|
|
|
|
var err error
|
|
|
|
|
2024-12-14 10:47:08 -06:00
|
|
|
pfile, err = os.ReadFile(REPOMAP)
|
2024-01-12 04:44:36 -06:00
|
|
|
if err != nil {
|
2024-10-08 11:36:46 -05:00
|
|
|
log.Error(err, "no repository map file found in /etc/gowebd/")
|
|
|
|
log.Error(err, "falling back to the repository map file built into the gowebd binary")
|
|
|
|
pfile, err = resources.ReadFile("resources/repomap")
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err, "missing repomap in the binary")
|
|
|
|
return
|
|
|
|
}
|
2024-01-12 04:44:36 -06:00
|
|
|
}
|
2024-01-12 13:52:55 -06:00
|
|
|
configfile = strings.Split(string(pfile), "\n")
|
|
|
|
for _, line := range configfile {
|
2024-01-12 04:44:36 -06:00
|
|
|
fields := strings.Fields(line)
|
2024-01-31 08:45:58 -06:00
|
|
|
if len(fields) < 2 {
|
2024-01-12 04:44:36 -06:00
|
|
|
continue
|
|
|
|
}
|
2024-12-14 11:27:54 -06:00
|
|
|
gopath := fields[0]
|
|
|
|
giturl := fields[1]
|
|
|
|
repoMap[gopath] = giturl
|
2024-01-12 11:13:26 -06:00
|
|
|
|
2024-12-18 03:35:08 -06:00
|
|
|
repo := forge.FindByGoPath(gopath)
|
2024-12-14 10:47:08 -06:00
|
|
|
if repo != nil {
|
2024-12-27 20:43:23 -06:00
|
|
|
gitMap[gopath] = repo
|
2024-12-14 10:47:08 -06:00
|
|
|
} else {
|
|
|
|
log.Info("repo =", gopath, "real url =", repoMap[gopath], "not found")
|
|
|
|
}
|
2024-01-12 04:44:36 -06:00
|
|
|
}
|
|
|
|
}
|