diff options
| author | Jeff Carr <[email protected]> | 2024-01-31 08:45:58 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-01-31 08:45:58 -0600 |
| commit | 424c8d5a36e272ccedb2a6717c2a3d08b2ea1768 (patch) | |
| tree | c3ae81966d601dcb9a5fc49f1cbc135262e26d27 | |
| parent | 9ff813b0ad6a68c2aad8f6a7365b452a19c07457 (diff) | |
add versions and timestamps
Signed-off-by: Jeff Carr <[email protected]>
| -rw-r--r-- | Makefile | 3 | ||||
| -rw-r--r-- | dumpClient.go | 9 | ||||
| -rw-r--r-- | files/repomap | 3 | ||||
| -rw-r--r-- | indexHtml.go | 60 | ||||
| -rw-r--r-- | jsonClient.go | 7 | ||||
| -rw-r--r-- | main.go | 60 | ||||
| -rw-r--r-- | repoHTML.go | 61 |
7 files changed, 151 insertions, 52 deletions
@@ -6,6 +6,9 @@ all: ./go.wit.com @# ./myrepos >/tmp/myrepos.stderr 2>&1 +goimports: + goimports -w *.go + redomod: rm -f go.* GO111MODULE= go mod init diff --git a/dumpClient.go b/dumpClient.go index 2b5dcf4..188a8d7 100644 --- a/dumpClient.go +++ b/dumpClient.go @@ -2,9 +2,9 @@ package main import ( "fmt" - "time" - "net/http" "io/ioutil" + "net/http" + "time" "go.wit.com/log" ) @@ -32,9 +32,8 @@ func dumpClient(r *http.Request) { fmt.Fprintln(clientf, "Host:", r.Host) fmt.Fprintln(clientf, "Remote Address:", r.RemoteAddr) - // Headers - fmt.Fprintln(clientf,"Headers:") + fmt.Fprintln(clientf, "Headers:") for name, values := range r.Header { for _, value := range values { fmt.Fprintln(clientf, "Headers:", name, value) @@ -56,7 +55,7 @@ func dumpClient(r *http.Request) { fmt.Fprintln(clientf, "Content Length:", r.ContentLength) // Cookies - fmt.Fprintln(clientf,"Cookies:") + fmt.Fprintln(clientf, "Cookies:") for _, cookie := range r.Cookies() { fmt.Fprintln(clientf, cookie.Name, cookie.Value) } diff --git a/files/repomap b/files/repomap index 5f4cf3e..84ec168 100644 --- a/files/repomap +++ b/files/repomap @@ -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/basicwindow git.wit.org/jcarr/basicwindow 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-digitalocean git.wit.org/wit/control-panel-digitalocean go.wit.com/apps/control-panel-cloudflare git.wit.org/wit/control-panel-cloudflare diff --git a/indexHtml.go b/indexHtml.go index 1fca005..3fe8d9c 100644 --- a/indexHtml.go +++ b/indexHtml.go @@ -2,8 +2,10 @@ package main import ( "fmt" - "strings" "net/http" + "strconv" + "strings" + "time" "go.wit.com/log" ) @@ -34,22 +36,25 @@ func indexBodyStart(w http.ResponseWriter) { 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, " <thead>") fmt.Fprintln(w, " <tr>") 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>Authoritative sources (IPv6 only)</th>") fmt.Fprintln(w, " <th></th>") fmt.Fprintln(w, " <th>Documentation</th>") fmt.Fprintln(w, " </tr>") -// fmt.Fprintln(w, " </thead>") + // 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> </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) { @@ -57,15 +62,15 @@ func indexBodyScanConfig(w http.ResponseWriter) { for i, line := range configfile { // log.Info("config file line:", i, line) fields := strings.Fields(line) - if (len(fields) == 0) { + if len(fields) == 0 { continue } - if (fields[0] == "#") { + if fields[0] == "#" { insertHTMLnote(w, i, fields[0:]) // log.Info("comment # line:", i, line) continue } - if (len(fields) == 2) { + if len(fields) == 2 { log.Info("short file line:", i, line) gourl := fields[0] giturl := fields[1] @@ -80,15 +85,48 @@ func indexBodyScanConfig(w http.ResponseWriter) { 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>") - fmt.Fprintln(w, " <td>" + gourl + "</td>") - fmt.Fprintln(w, " <td> <a href=\"//" + gourl + "\">" + gourl + "</a></td>") - fmt.Fprintln(w, " <td> <a href=\"//" + gourl + "\">" + giturl + "</a></td>") + fmt.Fprintln(w, " <td>"+gourl+"</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 { + 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 == "" { fmt.Fprintln(w, " <td></td>") } 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=\"//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, "") } diff --git a/jsonClient.go b/jsonClient.go index 756fae7..4dc9b10 100644 --- a/jsonClient.go +++ b/jsonClient.go @@ -1,9 +1,9 @@ package main import ( - "io/ioutil" "bytes" "encoding/json" + "io/ioutil" "net/http" ) @@ -33,7 +33,7 @@ func dumpJsonClient(r *http.Request) (string, error) { var bodyBytes []byte if r.Body != nil { // Read the body if it's not nil bodyBytes, _ = ioutil.ReadAll(r.Body) - r.Body.Close() // Close the body when done reading + r.Body.Close() // Close the body when done reading r.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes)) // Reset the body } @@ -46,7 +46,7 @@ func dumpJsonClient(r *http.Request) (string, error) { Headers: r.Header, Cookies: cookieMap, QueryParams: r.URL.Query(), - Body: string(bodyBytes), + Body: string(bodyBytes), } // Marshal the struct to a JSON string @@ -68,6 +68,7 @@ func dumpJsonClient(r *http.Request) (string, error) { return string(formattedJSON), nil } + /* package main @@ -1,12 +1,14 @@ package main import ( - "os" + "embed" "fmt" - "go.wit.com/log" "net/http" - "embed" + "os" "strings" + "time" + + "go.wit.com/log" ) //go:embed files/* @@ -14,6 +16,11 @@ var htmlFiles embed.FS 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 '/' func cleanURL(url string) string { url = "/" + strings.Trim(url, "/") @@ -77,7 +84,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) { func findFile(w http.ResponseWriter, filename string) { // fmt.Fprintln(w, "GOT TEST?") pfile, err := htmlFiles.ReadFile(filename) - if (err != nil) { + if err != nil { log.Println("ERROR:", err) // w.Write(pfile) return @@ -89,19 +96,25 @@ func findFile(w http.ResponseWriter, filename string) { log.Println("findFile() found internal file:", filename) // w.Close() /* - filename = "/tmp/" + name + ".so" - log.Error(err, "write out file here", name, filename, len(pfile)) - f, _ := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE, 0600) - f.Close() + filename = "/tmp/" + name + ".so" + log.Error(err, "write out file here", name, filename, len(pfile)) + f, _ := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE, 0600) + f.Close() */ } func main() { - 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) + 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) 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) - https() + go https() err := http.ListenAndServe(":80", nil) if err != nil { log.Println("Error starting server:", err) @@ -122,3 +135,28 @@ func badurl(w http.ResponseWriter, badurl string) { fmt.Fprintln(w, " </body>") 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 +} diff --git a/repoHTML.go b/repoHTML.go index 0cba639..24b20c5 100644 --- a/repoHTML.go +++ b/repoHTML.go @@ -1,13 +1,16 @@ package main import ( + "bufio" "fmt" - "strings" - "go.wit.com/log" "net/http" + "os" + "path/filepath" "sort" -) + "strings" + "go.wit.com/log" +) /* <!DOCTYPE html> @@ -29,32 +32,28 @@ func repoHTML(w http.ResponseWriter, gourl string, realurl string) { fmt.Fprintln(w, "<!DOCTYPE html>") fmt.Fprintln(w, "<html>") fmt.Fprintln(w, "<head>") - // 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}", "\"", ">") + // 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}", "\"", ">") - 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, "<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, "</html>") /* - var tmp string - tmp = r.URL.String() - if tmp == "/gui" { - findFile(w) - return - } - fmt.Fprintln(w, "OK") + var tmp string + tmp = r.URL.String() + if tmp == "/gui" { + findFile(w) + return + } + fmt.Fprintln(w, "OK") */ } -var repoMap map[string]string -var configfile []string -var keysSorted []string - func findkey(url string) (string, string) { key := "go.wit.com" + url if repoMap[key] != "" { @@ -74,7 +73,7 @@ func readconfigfile() { configfile = strings.Split(string(pfile), "\n") for _, line := range configfile { fields := strings.Fields(line) - if (len(fields) < 2) { + if len(fields) < 2 { continue } repo := fields[0] @@ -84,7 +83,6 @@ func readconfigfile() { // log.Info("repo =", repo, "real url =", realurl) } - for repo, _ := range repoMap { // log.Info("repo =", repo, "real url =", url) keysSorted = append(keysSorted, repo) @@ -97,3 +95,24 @@ func readconfigfile() { 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:], " ") + } +} |
