diff --git a/Makefile b/Makefile index 8381034..4b3227e 100644 --- a/Makefile +++ b/Makefile @@ -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, "
") fmt.Fprintln(w, "
") fmt.Fprintln(w, " ") -// fmt.Fprintln(w, " ") + // fmt.Fprintln(w, " ") fmt.Fprintln(w, " ") fmt.Fprintln(w, " ") + fmt.Fprintln(w, " ") + fmt.Fprintln(w, " ") + fmt.Fprintln(w, " ") fmt.Fprintln(w, " ") fmt.Fprintln(w, " ") fmt.Fprintln(w, " ") fmt.Fprintln(w, " ") fmt.Fprintln(w, " ") -// fmt.Fprintln(w, " ") + // fmt.Fprintln(w, " ") fmt.Fprintln(w, " ") fmt.Fprintln(w, "") } func insertHTMLnote(w http.ResponseWriter, i int, parts []string) { log.Info("comment # line:", i, strings.Join(parts, " ")) - fmt.Fprintln(w, " ") + fmt.Fprintln(w, " ") } 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, " ") fmt.Fprintln(w, " ") - fmt.Fprintln(w, " ") - fmt.Fprintln(w, " ") - fmt.Fprintln(w, " ") + fmt.Fprintln(w, " ") + 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, " ") // version + fmt.Fprintln(w, " ") // dev version + fmt.Fprintln(w, " ") // dev version + fmt.Fprintln(w, " ") + fmt.Fprintln(w, " ") if github == "" { fmt.Fprintln(w, " ") } else { fmt.Fprintln(w, " ") } - fmt.Fprintln(w, " ") + fmt.Fprintln(w, " ") fmt.Fprintln(w, " ") 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 diff --git a/main.go b/main.go index 67891c8..0e1b544 100644 --- a/main.go +++ b/main.go @@ -1,12 +1,14 @@ package main import ( - "os" - "fmt" - "go.wit.com/log" - "net/http" "embed" + "fmt" + "net/http" + "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, " ") fmt.Fprintln(w, "") } + +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" +) /* @@ -29,32 +32,28 @@ func repoHTML(w http.ResponseWriter, gourl string, realurl string) { fmt.Fprintln(w, "") fmt.Fprintln(w, "") fmt.Fprintln(w, "") - // fmt.Fprintln(w, - fmt.Fprintln(w, "") - fmt.Fprintln(w, "") + // fmt.Fprintln(w, + fmt.Fprintln(w, "") + fmt.Fprintln(w, "") - fmt.Fprintln(w, "") + fmt.Fprintln(w, "") fmt.Fprintln(w, "") fmt.Fprintln(w, "") - fmt.Fprintln(w, "Nothing to see here. Please move along.\"") + fmt.Fprintln(w, "Nothing to see here. Please move along.\"") fmt.Fprintln(w, "") fmt.Fprintln(w, "") /* - 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:], " ") + } +}
PackageVersionAgeDev Versiongo getAuthoritative sources (IPv6 only)Documentation

", strings.Join(parts, " "), "

", strings.Join(parts, " "), "

log/ (needed for the gui)
" + gourl + " " + gourl + " " + giturl + ""+gourl+""+version+""+ vtime +" "+gourl+" "+giturl+" github.com/wit-go/log \"pkg.go.dev \"pkg.go.dev