2024-01-12 04:14:09 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-01-31 08:45:58 -06:00
|
|
|
"bufio"
|
2024-01-12 04:14:09 -06:00
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2024-01-31 08:45:58 -06:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2024-01-12 11:13:26 -06:00
|
|
|
"sort"
|
2024-01-31 08:45:58 -06:00
|
|
|
"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
|
|
|
|
|
|
|
/*
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta name="go-import" content="go.wit.com/gui/gui git https://git.wit.org/gui/gui">
|
|
|
|
<meta name="go-source" content="go.wit.com/gui/gui https://git.wit.org/gui/gui https://git.wit.org/gui/tree/master{/dir} https://git.wit.org/gui/gui/tree/master{/dir}/{file}#L{line}">
|
|
|
|
<meta http-equiv="refresh" content="0; url=https://git.wit.org/gui/gui">
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
Nothing to see here. Please <a href="https://git.wit.org/gui/gui">move along</a>.
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
*/
|
|
|
|
|
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-31 08:45:58 -06:00
|
|
|
var tmp string
|
|
|
|
tmp = r.URL.String()
|
|
|
|
if tmp == "/gui" {
|
|
|
|
findFile(w)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fmt.Fprintln(w, "OK")
|
2024-01-12 04:14:09 -06:00
|
|
|
*/
|
|
|
|
}
|
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-01-12 04:44:36 -06:00
|
|
|
func readconfigfile() {
|
2024-01-12 11:13:26 -06:00
|
|
|
repoMap = make(map[string]string)
|
2024-01-12 04:44:36 -06:00
|
|
|
pfile, err := htmlFiles.ReadFile("files/repomap")
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err, "missing repomap in the binary")
|
|
|
|
return
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
repo := fields[0]
|
|
|
|
realurl := fields[1]
|
2024-01-12 11:13:26 -06:00
|
|
|
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 _, key := range keysSorted {
|
|
|
|
log.Info("repo =", key, "real url =", repoMap[key])
|
2024-01-12 04:44:36 -06:00
|
|
|
}
|
|
|
|
}
|
2024-01-31 08:45:58 -06:00
|
|
|
|
|
|
|
func readVersionFile() {
|
|
|
|
versionMap = make(map[string]string)
|
|
|
|
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.Split(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:], " ")
|
|
|
|
}
|
|
|
|
}
|