summaryrefslogtreecommitdiff
path: root/indexHtml.go
blob: 08c2014ce9bcc24786d060a70ccde603a7a1d25b (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package main

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

func indexHeader(w http.ResponseWriter) {
	fmt.Fprintln(w, "<!DOCTYPE html>")
	fmt.Fprintln(w, "<html>")
	fmt.Fprintln(w, "    <head>")
	// fmt.Fprintln(w, "        <link rel=\"stylesheet\" href=\"skeleton.v2.css\" />")
	fmt.Fprintln(w, "    <style>")
	fmt.Fprintln(w, "        #footer {")
	fmt.Fprintln(w, "            position: fixed;")
	fmt.Fprintln(w, "            padding: 1% 0% 1% 0%; /* top left bottom right */")
	fmt.Fprintln(w, "            bottom: 0;")
	fmt.Fprintln(w, "            width: 100%;")
	fmt.Fprintln(w, "            /* Height of the footer*/")
	fmt.Fprintln(w, "            height: 40px;")
	fmt.Fprintln(w, "            background: lightgrey;")
	fmt.Fprintln(w, "        }")
	fmt.Fprintln(w, "    </style>")
	fmt.Fprintln(w, "    </head>")
	fmt.Fprintln(w, "</html>")
}

func indexBodyStart(w http.ResponseWriter) {
	// fmt.Fprintln(w, "
	fmt.Fprintln(w, "<body>")
	fmt.Fprintln(w, " <br>")
	fmt.Fprintln(w, "There are debian packages for most of these on mirrors.wit.com<br>")
	fmt.Fprintln(w, " <br>")
	fmt.Fprintln(w, " <br>")
	fmt.Fprintln(w, "    <div class=\"container\">")
	fmt.Fprintln(w, "    <div class=\"row\">")
	fmt.Fprintln(w, "        <table class=\"u-full-width\">")
	//	fmt.Fprintln(w, "        <thead>")
	fmt.Fprintln(w, "        <tr>")
	fmt.Fprintln(w, "            <th>Package (IPv6 only)</th>")
	fmt.Fprintln(w, "            <th>Documentation</th>")
	fmt.Fprintln(w, "            <th>Version</th>")
	fmt.Fprintln(w, "            <th>Age</th>")
	fmt.Fprintln(w, "            <th>Dev Version</th>")
	fmt.Fprintln(w, "            <th>Description</th>")
	// fmt.Fprintln(w, "            <th>Authoritative sources (IPv6 only)</th>")
	// fmt.Fprintln(w, "            <th></th>")
	fmt.Fprintln(w, "        </tr>")
	//	fmt.Fprintln(w, "        </thead>")
	fmt.Fprintln(w, "    <tbody>")
	fmt.Fprintln(w, "")
}

func insertHTMLnote(w http.ResponseWriter, i int, parts []string) {
	// log.Info("comment #   line:", i, strings.Join(parts, " "))
	fmt.Fprintln(w, " <tr> <td><h3>", strings.Join(parts, " "), "</h3></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr>")
}

func indexBodyScanConfig(w http.ResponseWriter) {
	// log.Info("indexBodyScanConfig() START")
	for i, line := range configfile {
		// log.Info("config file line:", i, line)
		fields := strings.Fields(line)
		if len(fields) == 0 {
			continue
		}
		if fields[0] == "#" {
			insertHTMLnote(w, i, fields[0:])
			// log.Info("comment #   line:", i, line)
			continue
		}
		if len(fields) == 2 {
			// log.Info("short  file line:", i, line)
			gourl := fields[0]
			giturl := fields[1]
			indexBodyRepo(w, gourl, giturl, "")
			continue
		}
		if len(fields) > 2 {
			// log.Info("short  file line:", i, line)
			gourl := fields[0]
			giturl := fields[1]
			desc := strings.Join(fields[2:], " ")
			desc = strings.TrimSpace(desc)
			indexBodyRepo(w, gourl, giturl, desc)
			continue
		}
		// log.Info("config file line:", i, line)
	}
	// log.Info("indexBodyScanConfig() END")
}

func indexBodyRepo(w http.ResponseWriter, gourl string, giturl string, desc string) {
	// skip displaying packages without a desc
	if desc == "" {
		return
	}
	// fmt.Fprintln(w, " <tr> <td><h5>log/ (needed for the gui)</h5></td> <td></td> <td></td> <td></td> <td></td> </tr>")
	fmt.Fprintln(w, " <tr>")
	// fmt.Fprintln(w, " <td>"+gourl+"</td>")
	fmt.Fprintln(w, " <td> <a href=\"//"+gourl+"\">"+gourl+"</a></td>")
	fmt.Fprintln(w, " <td> <a href=\"//pkg.go.dev/"+gourl+"\"> <img src=\"goReference.svg\" alt=\"pkg.go.dev\" /> </a> </td>")
	// for i, s := range versionMap {
	// 	log.Println("found i =", i, "with", "s =", s)
	// }
	var vtime, version string
	gourl = strings.TrimSpace(gourl)
	tmp, _ := versionMap[gourl]
	parts := strings.Split(tmp, " ")
	if len(parts) > 0 {
		vtime = parts[0]
	}
	if len(parts) > 1 {
		version = parts[1]
	}
	log.Warn("gourl ", gourl, "vtime =", vtime, "version =", version)

	if vtime != "" {
		// Convert the string to an integer
		gitTagTimestampInt, _ := strconv.ParseInt(vtime, 10, 64)

		// Parse the Unix timestamp into a time.Time object
		gitTagDate := time.Unix(gitTagTimestampInt, 0)

		// Get the current time
		currentTime := time.Now()

		// Calculate the duration between the git tag date and the current time
		duration := currentTime.Sub(gitTagDate)

		vtime = formatDuration(duration)
	}

	fmt.Fprintln(w, " <td>"+version+"</td>") // version
	fmt.Fprintln(w, " <td>"+vtime+"</td>")   // dev version
	if gourl == "go.wit.com/apps/helloworld" {
		fmt.Fprintln(w, " <td><a href=\"http://mirrors.wit.com/guidemo/helloworld-demo.webm\">Video Demo</a> </td>") // dev version
	} else {
		fmt.Fprintln(w, " <td></td>") // dev version
	}
	fmt.Fprintln(w, " <td>"+desc+"</td>")
	// fmt.Fprintln(w, " <td> <a href=\"//"+gourl+"\">"+giturl+"</a></td>")
	fmt.Fprintln(w, " </tr>")
	fmt.Fprintln(w, "")
}

func indexDivEnd(w http.ResponseWriter) {
	// fmt.Fprintln(w, "
	fmt.Fprintln(w, " </tbody>")
	fmt.Fprintln(w, " </table>")
	fmt.Fprintln(w, " </div>")
	fmt.Fprintln(w, " </div>")
}

func indexBodyEnd(w http.ResponseWriter) {
	fmt.Fprintln(w, " <br>")
	fmt.Fprintln(w, "echo deb http://mirrors.wit.com/wit/ sid main > /etc/apt/sources.list.d/wit.list <br>")
	fmt.Fprintln(w, "apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4A854AEAF7E0E16D <br>")
	fmt.Fprintln(w, "apt update<br>")
	fmt.Fprintln(w, "apt install go-clone # replicates the old 'go get' behavior<br>")
	fmt.Fprintln(w, "apt install go-deb   # make a debian package from a golang project<br>")
	fmt.Fprintln(w, "apt install networkquality   # debian package of apple's command line speedtest tool<br>")
	fmt.Fprintln(w, "apt install virtigo   # virt-manager from the command line (runs wit.com)<br>")
	fmt.Fprintln(w, " </body>")
	fmt.Fprintln(w, " </html>")
}