2024-01-12 12:26:05 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2024-01-31 08:45:58 -06:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"time"
|
2024-01-12 12:26:05 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func indexHeader(w http.ResponseWriter) {
|
|
|
|
fmt.Fprintln(w, "<!DOCTYPE html>")
|
|
|
|
fmt.Fprintln(w, "<html>")
|
|
|
|
fmt.Fprintln(w, " <head>")
|
2024-01-12 12:40:54 -06:00
|
|
|
// fmt.Fprintln(w, " <link rel=\"stylesheet\" href=\"skeleton.v2.css\" />")
|
2024-01-12 12:26:05 -06:00
|
|
|
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, "
|
2024-01-12 12:40:54 -06:00
|
|
|
fmt.Fprintln(w, "<body>")
|
|
|
|
fmt.Fprintln(w, " <div class=\"container\">")
|
|
|
|
fmt.Fprintln(w, " <div class=\"row\">")
|
|
|
|
fmt.Fprintln(w, " <table class=\"u-full-width\">")
|
2024-01-31 08:45:58 -06:00
|
|
|
// fmt.Fprintln(w, " <thead>")
|
2024-01-12 12:40:54 -06:00
|
|
|
fmt.Fprintln(w, " <tr>")
|
2024-02-10 07:34:58 -06:00
|
|
|
fmt.Fprintln(w, " <th>Package (IPv6 only)</th>")
|
2024-02-10 08:06:20 -06:00
|
|
|
fmt.Fprintln(w, " <th>Documentation</th>")
|
2024-01-31 08:45:58 -06:00
|
|
|
fmt.Fprintln(w, " <th>Version</th>")
|
|
|
|
fmt.Fprintln(w, " <th>Age</th>")
|
|
|
|
fmt.Fprintln(w, " <th>Dev Version</th>")
|
2024-02-10 07:34:58 -06:00
|
|
|
fmt.Fprintln(w, " <th>Description</th>")
|
|
|
|
// fmt.Fprintln(w, " <th>Authoritative sources (IPv6 only)</th>")
|
|
|
|
// fmt.Fprintln(w, " <th></th>")
|
2024-01-12 12:40:54 -06:00
|
|
|
fmt.Fprintln(w, " </tr>")
|
2024-01-31 08:45:58 -06:00
|
|
|
// fmt.Fprintln(w, " </thead>")
|
2024-01-12 12:40:54 -06:00
|
|
|
fmt.Fprintln(w, " <tbody>")
|
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
}
|
|
|
|
|
2024-01-12 13:52:55 -06:00
|
|
|
func insertHTMLnote(w http.ResponseWriter, i int, parts []string) {
|
2024-02-07 22:14:38 -06:00
|
|
|
// log.Info("comment # line:", i, strings.Join(parts, " "))
|
2024-01-31 08:45:58 -06:00
|
|
|
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>")
|
2024-01-12 13:52:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func indexBodyScanConfig(w http.ResponseWriter) {
|
2024-02-10 07:34:58 -06:00
|
|
|
// log.Info("indexBodyScanConfig() START")
|
2024-01-12 13:52:55 -06:00
|
|
|
for i, line := range configfile {
|
|
|
|
// log.Info("config file line:", i, line)
|
|
|
|
fields := strings.Fields(line)
|
2024-01-31 08:45:58 -06:00
|
|
|
if len(fields) == 0 {
|
2024-01-12 13:52:55 -06:00
|
|
|
continue
|
|
|
|
}
|
2024-01-31 08:45:58 -06:00
|
|
|
if fields[0] == "#" {
|
2024-01-12 13:52:55 -06:00
|
|
|
insertHTMLnote(w, i, fields[0:])
|
|
|
|
// log.Info("comment # line:", i, line)
|
|
|
|
continue
|
|
|
|
}
|
2024-01-31 08:45:58 -06:00
|
|
|
if len(fields) == 2 {
|
2024-02-10 07:34:58 -06:00
|
|
|
// log.Info("short file line:", i, line)
|
2024-01-12 13:52:55 -06:00
|
|
|
gourl := fields[0]
|
|
|
|
giturl := fields[1]
|
|
|
|
indexBodyRepo(w, gourl, giturl, "")
|
|
|
|
continue
|
|
|
|
}
|
2024-02-10 07:34:58 -06:00
|
|
|
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)
|
2024-01-12 13:52:55 -06:00
|
|
|
}
|
2024-02-10 07:34:58 -06:00
|
|
|
// log.Info("indexBodyScanConfig() END")
|
2024-01-12 13:52:55 -06:00
|
|
|
}
|
|
|
|
|
2024-02-10 07:34:58 -06:00
|
|
|
func indexBodyRepo(w http.ResponseWriter, gourl string, giturl string, desc string) {
|
2024-02-10 07:46:25 -06:00
|
|
|
// skip displaying packages without a desc
|
|
|
|
if desc == "" {
|
|
|
|
return
|
|
|
|
}
|
2024-01-12 13:52:55 -06:00
|
|
|
// fmt.Fprintln(w, " <tr> <td><h5>log/ (needed for the gui)</h5></td> <td></td> <td></td> <td></td> <td></td> </tr>")
|
2024-01-12 12:26:05 -06:00
|
|
|
fmt.Fprintln(w, " <tr>")
|
2024-02-10 07:34:58 -06:00
|
|
|
// fmt.Fprintln(w, " <td>"+gourl+"</td>")
|
|
|
|
fmt.Fprintln(w, " <td> <a href=\"//"+gourl+"\">"+gourl+"</a></td>")
|
2024-02-10 08:06:20 -06:00
|
|
|
fmt.Fprintln(w, " <td> <a href=\"//pkg.go.dev/"+gourl+"\"> <img src=\"goReference.svg\" alt=\"pkg.go.dev\" /> </a> </td>")
|
2024-02-10 07:34:58 -06:00
|
|
|
// for i, s := range versionMap {
|
|
|
|
// log.Println("found i =", i, "with", "s =", s)
|
|
|
|
// }
|
2024-01-31 08:45:58 -06:00
|
|
|
var vtime, version string
|
|
|
|
gourl = strings.TrimSpace(gourl)
|
|
|
|
tmp, _ := versionMap[gourl]
|
|
|
|
parts := strings.Split(tmp, " ")
|
|
|
|
if len(parts) > 0 {
|
|
|
|
version = parts[0]
|
|
|
|
}
|
|
|
|
if len(parts) > 1 {
|
|
|
|
vtime = parts[1]
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2024-02-10 07:34:58 -06:00
|
|
|
fmt.Fprintln(w, " <td>"+vtime+"</td>") // dev version
|
2024-02-13 15:34:12 -06:00
|
|
|
if gourl == "go.wit.com/apps/helloworld" {
|
2024-02-13 16:14:22 -06:00
|
|
|
fmt.Fprintln(w, " <td><a href=\"http://mirrors.wit.com/guidemo/helloworld-demo.webm\">Video Demo</a> </td>") // dev version
|
2024-02-13 15:34:12 -06:00
|
|
|
} else {
|
2024-02-13 16:14:22 -06:00
|
|
|
fmt.Fprintln(w, " <td></td>") // dev version
|
2024-02-13 15:34:12 -06:00
|
|
|
}
|
2024-02-10 07:34:58 -06:00
|
|
|
fmt.Fprintln(w, " <td>"+desc+"</td>")
|
|
|
|
// fmt.Fprintln(w, " <td> <a href=\"//"+gourl+"\">"+giturl+"</a></td>")
|
2024-01-12 12:26:05 -06:00
|
|
|
fmt.Fprintln(w, " </tr>")
|
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
}
|
|
|
|
|
2024-01-15 16:28:03 -06:00
|
|
|
func indexDivEnd(w http.ResponseWriter) {
|
2024-01-12 12:26:05 -06:00
|
|
|
// fmt.Fprintln(w, "
|
|
|
|
fmt.Fprintln(w, " </tbody>")
|
|
|
|
fmt.Fprintln(w, " </table>")
|
|
|
|
fmt.Fprintln(w, " </div>")
|
|
|
|
fmt.Fprintln(w, " </div>")
|
2024-01-15 16:28:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func indexBodyEnd(w http.ResponseWriter) {
|
2024-01-12 12:26:05 -06:00
|
|
|
fmt.Fprintln(w, " </body>")
|
|
|
|
fmt.Fprintln(w, " </html>")
|
|
|
|
}
|