summaryrefslogtreecommitdiff
path: root/repomap.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-12-14 10:47:08 -0600
committerJeff Carr <[email protected]>2024-12-14 10:47:08 -0600
commitdead6fe01f7599fc3b6a6b1ee77a9e69e7b325d1 (patch)
treee28026f0e331b4c7e80e3fb83f92e191298953eb /repomap.go
parent0775662416320c07651061e6e59b0cae217a9e2b (diff)
new args. use forgepb for versions and dates
Diffstat (limited to 'repomap.go')
-rw-r--r--repomap.go123
1 files changed, 123 insertions, 0 deletions
diff --git a/repomap.go b/repomap.go
new file mode 100644
index 0000000..b70f894
--- /dev/null
+++ b/repomap.go
@@ -0,0 +1,123 @@
+package main
+
+// parses /etc/gowebd/repomap
+// this file defines what repositories show up on go.wit.com
+
+import (
+ "bufio"
+ "fmt"
+ "net/http"
+ "os"
+ "path/filepath"
+ "sort"
+ "strings"
+
+ "go.wit.com/log"
+)
+
+// 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"
+func repoHTML(w http.ResponseWriter, gourl string, realurl string) {
+ realurl = "https://" + realurl
+ log.Info("go repo =", gourl, "real url =", realurl)
+ fmt.Fprintln(w, "<!DOCTYPE html>")
+ fmt.Fprintln(w, "<html>")
+ fmt.Fprintln(w, "<head>")
+ // 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}", "\"", ">")
+
+ fmt.Fprintln(w, "<meta http-equiv=\"refresh\" content=\"0; url="+realurl+"\">")
+ fmt.Fprintln(w, "</head>")
+ fmt.Fprintln(w, "<body>")
+ fmt.Fprintln(w, "Nothing to see here. Please <a href=\""+realurl+"\">move along</a>.\"")
+ fmt.Fprintln(w, "</body>")
+ fmt.Fprintln(w, "</html>")
+}
+
+func findkey(url string) (string, string) {
+ key := "go.wit.com" + url
+ if repoMap[key] != "" {
+ return key, repoMap[key]
+ }
+ return key, ""
+ // parts := strings.Split(key, "/")
+}
+
+func readRepomap() {
+ var pfile []byte
+ var err error
+ repoMap = make(map[string]string)
+
+ pfile, err = os.ReadFile(REPOMAP)
+ if err != nil {
+ 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
+ }
+ }
+ configfile = strings.Split(string(pfile), "\n")
+ for _, line := range configfile {
+ fields := strings.Fields(line)
+ if len(fields) < 2 {
+ continue
+ }
+ repo := fields[0]
+ realurl := fields[1]
+ repoMap[repo] = realurl
+
+ // log.Info("repo =", repo, "real url =", realurl)
+ }
+
+ for repo, _ := range repoMap {
+ // log.Info("repo =", repo, "real url =", url)
+ keysSorted = append(keysSorted, repo)
+ }
+ log.Info("sorted:")
+ sort.Strings(keysSorted)
+ // sort.Reverse(keys)
+ sort.Sort(sort.Reverse(sort.StringSlice(keysSorted)))
+ for _, gopath := range keysSorted {
+ repo := forge.Repos.FindByGoPath(gopath)
+ if repo != nil {
+ version := repo.GetLastTag()
+ age := forge.NewestAge(repo)
+ log.Info("repo =", gopath, "real url =", repoMap[gopath], version, formatDuration(age))
+ versionMap[gopath] = version + " " + formatDuration(age)
+ /*
+ all := repo.Tags.SortByAge()
+ for all.Scan() {
+ r := all.Next()
+ dur := time.Since(r.GetAuthordate().AsTime())
+ name := r.Refname
+ log.Info("tag =", name, formatDuration(dur))
+ }
+ */
+ } else {
+ log.Info("repo =", gopath, "real url =", repoMap[gopath], "not found")
+ }
+ }
+}
+
+func readVersionFile() {
+ file, err := os.Open(filepath.Join(os.Getenv("HOME"), "go.wit.com.versions"))
+ if err != nil {
+ return
+ }
+ defer file.Close()
+
+ scanner := bufio.NewScanner(file)
+ for scanner.Scan() {
+ tmp := scanner.Text()
+ fields := strings.Fields(tmp)
+ if len(fields) < 2 {
+ continue
+ }
+ log.Println("readVersionFile() fields[0] =", fields[0])
+ // log.Println("readVersionFile() fields[1:] =", fields[1:])
+ versionMap[fields[0]] = strings.Join(fields[1:], " ")
+ }
+}