add versions and timestamps

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-31 08:45:58 -06:00
parent 9ff813b0ad
commit 424c8d5a36
7 changed files with 152 additions and 53 deletions

View File

@ -6,6 +6,9 @@ all:
./go.wit.com ./go.wit.com
@# ./myrepos >/tmp/myrepos.stderr 2>&1 @# ./myrepos >/tmp/myrepos.stderr 2>&1
goimports:
goimports -w *.go
redomod: redomod:
rm -f go.* rm -f go.*
GO111MODULE= go mod init GO111MODULE= go mod init

View File

@ -2,9 +2,9 @@ package main
import ( import (
"fmt" "fmt"
"time"
"net/http"
"io/ioutil" "io/ioutil"
"net/http"
"time"
"go.wit.com/log" "go.wit.com/log"
) )
@ -32,9 +32,8 @@ func dumpClient(r *http.Request) {
fmt.Fprintln(clientf, "Host:", r.Host) fmt.Fprintln(clientf, "Host:", r.Host)
fmt.Fprintln(clientf, "Remote Address:", r.RemoteAddr) fmt.Fprintln(clientf, "Remote Address:", r.RemoteAddr)
// Headers // Headers
fmt.Fprintln(clientf,"Headers:") fmt.Fprintln(clientf, "Headers:")
for name, values := range r.Header { for name, values := range r.Header {
for _, value := range values { for _, value := range values {
fmt.Fprintln(clientf, "Headers:", name, value) fmt.Fprintln(clientf, "Headers:", name, value)
@ -56,7 +55,7 @@ func dumpClient(r *http.Request) {
fmt.Fprintln(clientf, "Content Length:", r.ContentLength) fmt.Fprintln(clientf, "Content Length:", r.ContentLength)
// Cookies // Cookies
fmt.Fprintln(clientf,"Cookies:") fmt.Fprintln(clientf, "Cookies:")
for _, cookie := range r.Cookies() { for _, cookie := range r.Cookies() {
fmt.Fprintln(clientf, cookie.Name, cookie.Value) fmt.Fprintln(clientf, cookie.Name, cookie.Value)
} }

View File

@ -31,7 +31,8 @@ go.wit.com/lib/protobuf/wit git.wit.org/wit/witProtobuf
go.wit.com/apps/helloworld git.wit.org/gui/helloworld go.wit.com/apps/helloworld git.wit.org/gui/helloworld
go.wit.com/apps/basicwindow git.wit.org/jcarr/basicwindow go.wit.com/apps/basicwindow git.wit.org/jcarr/basicwindow
go.wit.com/apps/gadgetwindow git.wit.org/jcarr/gadgetwindow go.wit.com/apps/gadgetwindow git.wit.org/jcarr/gadgetwindow
go.wit.com/apps/autotypist git.wit.org/jcarr/myrepos go.wit.com/apps/autotypist git.wit.org/jcarr/autotypist
go.wit.com/apps/guireleaser git.wit.org/jcarr/guireleaser
go.wit.com/apps/control-panel-dns git.wit.org/jcarr/control-panel-dns go.wit.com/apps/control-panel-dns git.wit.org/jcarr/control-panel-dns
go.wit.com/apps/control-panel-digitalocean git.wit.org/wit/control-panel-digitalocean go.wit.com/apps/control-panel-digitalocean git.wit.org/wit/control-panel-digitalocean
go.wit.com/apps/control-panel-cloudflare git.wit.org/wit/control-panel-cloudflare go.wit.com/apps/control-panel-cloudflare git.wit.org/wit/control-panel-cloudflare

View File

@ -2,8 +2,10 @@ package main
import ( import (
"fmt" "fmt"
"strings"
"net/http" "net/http"
"strconv"
"strings"
"time"
"go.wit.com/log" "go.wit.com/log"
) )
@ -34,22 +36,25 @@ func indexBodyStart(w http.ResponseWriter) {
fmt.Fprintln(w, " <div class=\"container\">") fmt.Fprintln(w, " <div class=\"container\">")
fmt.Fprintln(w, " <div class=\"row\">") fmt.Fprintln(w, " <div class=\"row\">")
fmt.Fprintln(w, " <table class=\"u-full-width\">") fmt.Fprintln(w, " <table class=\"u-full-width\">")
// fmt.Fprintln(w, " <thead>") // fmt.Fprintln(w, " <thead>")
fmt.Fprintln(w, " <tr>") fmt.Fprintln(w, " <tr>")
fmt.Fprintln(w, " <th>Package</th>") fmt.Fprintln(w, " <th>Package</th>")
fmt.Fprintln(w, " <th>Version</th>")
fmt.Fprintln(w, " <th>Age</th>")
fmt.Fprintln(w, " <th>Dev Version</th>")
fmt.Fprintln(w, " <th>go get</th>") fmt.Fprintln(w, " <th>go get</th>")
fmt.Fprintln(w, " <th>Authoritative sources (IPv6 only)</th>") fmt.Fprintln(w, " <th>Authoritative sources (IPv6 only)</th>")
fmt.Fprintln(w, " <th></th>") fmt.Fprintln(w, " <th></th>")
fmt.Fprintln(w, " <th>Documentation</th>") fmt.Fprintln(w, " <th>Documentation</th>")
fmt.Fprintln(w, " </tr>") fmt.Fprintln(w, " </tr>")
// fmt.Fprintln(w, " </thead>") // fmt.Fprintln(w, " </thead>")
fmt.Fprintln(w, " <tbody>") fmt.Fprintln(w, " <tbody>")
fmt.Fprintln(w, "") fmt.Fprintln(w, "")
} }
func insertHTMLnote(w http.ResponseWriter, i int, parts []string) { func insertHTMLnote(w http.ResponseWriter, i int, parts []string) {
log.Info("comment # line:", i, strings.Join(parts, " ")) 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> </tr>") 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) { func indexBodyScanConfig(w http.ResponseWriter) {
@ -57,15 +62,15 @@ func indexBodyScanConfig(w http.ResponseWriter) {
for i, line := range configfile { for i, line := range configfile {
// log.Info("config file line:", i, line) // log.Info("config file line:", i, line)
fields := strings.Fields(line) fields := strings.Fields(line)
if (len(fields) == 0) { if len(fields) == 0 {
continue continue
} }
if (fields[0] == "#") { if fields[0] == "#" {
insertHTMLnote(w, i, fields[0:]) insertHTMLnote(w, i, fields[0:])
// log.Info("comment # line:", i, line) // log.Info("comment # line:", i, line)
continue continue
} }
if (len(fields) == 2) { if len(fields) == 2 {
log.Info("short file line:", i, line) log.Info("short file line:", i, line)
gourl := fields[0] gourl := fields[0]
giturl := fields[1] giturl := fields[1]
@ -80,15 +85,48 @@ func indexBodyScanConfig(w http.ResponseWriter) {
func indexBodyRepo(w http.ResponseWriter, gourl string, giturl string, github string) { func indexBodyRepo(w http.ResponseWriter, gourl string, giturl string, github string) {
// 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> <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, " <tr>")
fmt.Fprintln(w, " <td>" + gourl + "</td>") fmt.Fprintln(w, " <td>"+gourl+"</td>")
fmt.Fprintln(w, " <td> <a href=\"//" + gourl + "\">" + gourl + "</a></td>") for i, s := range versionMap {
fmt.Fprintln(w, " <td> <a href=\"//" + gourl + "\">" + giturl + "</a></td>") 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 {
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
fmt.Fprintln(w, " <td>"+ vtime +"</td>") // dev version
fmt.Fprintln(w, " <td></td>") // dev version
fmt.Fprintln(w, " <td> <a href=\"//"+gourl+"\">"+gourl+"</a></td>")
fmt.Fprintln(w, " <td> <a href=\"//"+gourl+"\">"+giturl+"</a></td>")
if github == "" { if github == "" {
fmt.Fprintln(w, " <td></td>") fmt.Fprintln(w, " <td></td>")
} else { } else {
fmt.Fprintln(w, " <td> <a href=\"//github.com/wit-go/log\">github.com/wit-go/log</a></td>") fmt.Fprintln(w, " <td> <a href=\"//github.com/wit-go/log\">github.com/wit-go/log</a></td>")
} }
fmt.Fprintln(w, " <td> <a href=\"//pkg.go.dev/" + gourl + "\"> <img src=\"goReference.svg\" alt=\"pkg.go.dev docs\" /> </a> </td>") fmt.Fprintln(w, " <td> <a href=\"//pkg.go.dev/"+gourl+"\"> <img src=\"goReference.svg\" alt=\"pkg.go.dev docs\" /> </a> </td>")
fmt.Fprintln(w, " </tr>") fmt.Fprintln(w, " </tr>")
fmt.Fprintln(w, "") fmt.Fprintln(w, "")
} }

View File

@ -1,9 +1,9 @@
package main package main
import ( import (
"io/ioutil"
"bytes" "bytes"
"encoding/json" "encoding/json"
"io/ioutil"
"net/http" "net/http"
) )
@ -68,6 +68,7 @@ func dumpJsonClient(r *http.Request) (string, error) {
return string(formattedJSON), nil return string(formattedJSON), nil
} }
/* /*
package main package main

54
main.go
View File

@ -1,12 +1,14 @@
package main package main
import ( import (
"os"
"fmt"
"go.wit.com/log"
"net/http"
"embed" "embed"
"fmt"
"net/http"
"os"
"strings" "strings"
"time"
"go.wit.com/log"
) )
//go:embed files/* //go:embed files/*
@ -14,6 +16,11 @@ var htmlFiles embed.FS
var accessf, clientf *os.File var accessf, clientf *os.File
var repoMap map[string]string
var versionMap map[string]string
var configfile []string
var keysSorted []string
// remove '?' part and trailing '/' // remove '?' part and trailing '/'
func cleanURL(url string) string { func cleanURL(url string) string {
url = "/" + strings.Trim(url, "/") url = "/" + strings.Trim(url, "/")
@ -77,7 +84,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
func findFile(w http.ResponseWriter, filename string) { func findFile(w http.ResponseWriter, filename string) {
// fmt.Fprintln(w, "GOT TEST?") // fmt.Fprintln(w, "GOT TEST?")
pfile, err := htmlFiles.ReadFile(filename) pfile, err := htmlFiles.ReadFile(filename)
if (err != nil) { if err != nil {
log.Println("ERROR:", err) log.Println("ERROR:", err)
// w.Write(pfile) // w.Write(pfile)
return return
@ -97,11 +104,17 @@ func findFile(w http.ResponseWriter, filename string) {
} }
func main() { func main() {
accessf, _ = os.OpenFile("/home/jcarr/accessclient.log", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666) accessf, _ = os.OpenFile("/home/jcarr/accessclient.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
clientf, _ = os.OpenFile("/home/jcarr/httpclient.log", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666) clientf, _ = os.OpenFile("/home/jcarr/httpclient.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
readconfigfile() readconfigfile()
readVersionFile()
for i, s := range versionMap {
log.Println("found i =", i, "with", "s =", s)
}
log.Println("found log =", versionMap["go.wit.com/log"])
http.HandleFunc("/", okHandler) http.HandleFunc("/", okHandler)
https() go https()
err := http.ListenAndServe(":80", nil) err := http.ListenAndServe(":80", nil)
if err != nil { if err != nil {
log.Println("Error starting server:", err) log.Println("Error starting server:", err)
@ -122,3 +135,28 @@ func badurl(w http.ResponseWriter, badurl string) {
fmt.Fprintln(w, " </body>") fmt.Fprintln(w, " </body>")
fmt.Fprintln(w, "</html>") fmt.Fprintln(w, "</html>")
} }
func formatDuration(d time.Duration) string {
seconds := int(d.Seconds()) % 60
minutes := int(d.Minutes()) % 60
hours := int(d.Hours()) % 24
days := int(d.Hours()) / 24
result := ""
if days > 0 {
result += fmt.Sprintf("%dd ", days)
return result
}
if hours > 0 {
result += fmt.Sprintf("%dh ", hours)
return result
}
if minutes > 0 {
result += fmt.Sprintf("%dm ", minutes)
return result
}
if seconds > 0 {
result += fmt.Sprintf("%ds", seconds)
}
return result
}

View File

@ -1,13 +1,16 @@
package main package main
import ( import (
"bufio"
"fmt" "fmt"
"strings"
"go.wit.com/log"
"net/http" "net/http"
"os"
"path/filepath"
"sort" "sort"
) "strings"
"go.wit.com/log"
)
/* /*
<!DOCTYPE html> <!DOCTYPE html>
@ -30,13 +33,13 @@ func repoHTML(w http.ResponseWriter, gourl string, realurl string) {
fmt.Fprintln(w, "<html>") fmt.Fprintln(w, "<html>")
fmt.Fprintln(w, "<head>") fmt.Fprintln(w, "<head>")
// fmt.Fprintln(w, // fmt.Fprintln(w,
fmt.Fprintln(w, "<meta name=\"go-import\" content=\"", gourl, "git", realurl + "\">") 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 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, "<meta http-equiv=\"refresh\" content=\"0; url="+realurl+"\">")
fmt.Fprintln(w, "</head>") fmt.Fprintln(w, "</head>")
fmt.Fprintln(w, "<body>") fmt.Fprintln(w, "<body>")
fmt.Fprintln(w, "Nothing to see here. Please <a href=\"" + realurl + "\">move along</a>.\"") fmt.Fprintln(w, "Nothing to see here. Please <a href=\""+realurl+"\">move along</a>.\"")
fmt.Fprintln(w, "</body>") fmt.Fprintln(w, "</body>")
fmt.Fprintln(w, "</html>") fmt.Fprintln(w, "</html>")
@ -51,10 +54,6 @@ func repoHTML(w http.ResponseWriter, gourl string, realurl string) {
*/ */
} }
var repoMap map[string]string
var configfile []string
var keysSorted []string
func findkey(url string) (string, string) { func findkey(url string) (string, string) {
key := "go.wit.com" + url key := "go.wit.com" + url
if repoMap[key] != "" { if repoMap[key] != "" {
@ -74,7 +73,7 @@ func readconfigfile() {
configfile = strings.Split(string(pfile), "\n") configfile = strings.Split(string(pfile), "\n")
for _, line := range configfile { for _, line := range configfile {
fields := strings.Fields(line) fields := strings.Fields(line)
if (len(fields) < 2) { if len(fields) < 2 {
continue continue
} }
repo := fields[0] repo := fields[0]
@ -84,7 +83,6 @@ func readconfigfile() {
// log.Info("repo =", repo, "real url =", realurl) // log.Info("repo =", repo, "real url =", realurl)
} }
for repo, _ := range repoMap { for repo, _ := range repoMap {
// log.Info("repo =", repo, "real url =", url) // log.Info("repo =", repo, "real url =", url)
keysSorted = append(keysSorted, repo) keysSorted = append(keysSorted, repo)
@ -97,3 +95,24 @@ func readconfigfile() {
log.Info("repo =", key, "real url =", repoMap[key]) log.Info("repo =", key, "real url =", repoMap[key])
} }
} }
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:], " ")
}
}