summaryrefslogtreecommitdiff
path: root/repoHTML.go
blob: b9c9e29902c1208c6327c55d1587abefab6bdf7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main

import (
	"fmt"
	"strings"
	"go.wit.com/log"
	"net/http"
	"sort"
)


/*
<!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>
*/

func doGui(w http.ResponseWriter, gourl string, realurl string) {
	fmt.Fprintln(w, "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=\"", "go.wit.com/gui/gui", "git",  "https://git.wit.org/gui/gui\">")
	fmt.Fprintln(w, "<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}", "\"", ">")

	fmt.Fprintln(w, "<meta http-equiv=\"refresh\" content=\"0; url=", "https://git.wit.org/gui/gui", "\">")
	fmt.Fprintln(w, "</head>")
	fmt.Fprintln(w, "<body>")
	fmt.Fprintln(w, "Nothing to see here. Please <a href=\"https://git.wit.org/gui/gui\">move along</a>.\"")
	fmt.Fprintln(w, "</body>")
	fmt.Fprintln(w, "</html>")

	/*
	var tmp string
	tmp = r.URL.String()
	if tmp == "/gui" {
		findFile(w)
		return
	}
	fmt.Fprintln(w, "OK")
	*/
}

var repoMap map[string]string
var keysSorted []string

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 readconfigfile() {
	repoMap = make(map[string]string)
	pfile, err := htmlFiles.ReadFile("files/repomap")
	if err != nil {
		log.Error(err, "missing repomap in the binary")
		return
	}
	lines := strings.Split(string(pfile), "\n")
	for _, line := range lines {
		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 _, key := range keysSorted {
		log.Info("repo =", key, "real url =", repoMap[key])
	}
}