summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-10-06 09:48:35 -0500
committerJeff Carr <[email protected]>2024-10-06 09:48:35 -0500
commitf255120c10b7e5e40b420018988639aa5ce14d49 (patch)
tree7cd4f7f50431fadb8fc7d2a0f846f1257ffba116 /main.go
initial commit
Diffstat (limited to 'main.go')
-rw-r--r--main.go79
1 files changed, 79 insertions, 0 deletions
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..6aeb962
--- /dev/null
+++ b/main.go
@@ -0,0 +1,79 @@
+package main
+
+import (
+ "fmt"
+ "net/http"
+ "os"
+ "strings"
+ "time"
+
+ "go.wit.com/log"
+)
+
+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, "/")
+ return url
+}
+
+func okHandler(w http.ResponseWriter, r *http.Request) {
+ // dumpClient(r)
+ var tmp string
+ // tmp = r.URL.String()
+ tmp = cleanURL(r.URL.Path)
+ parts := strings.Split(tmp, "?")
+ log.Warn("URL =", tmp)
+ log.Info("client sent url =", tmp)
+ log.Info("parts are:", parts)
+ // requrl := parts[0]
+
+ if tmp == "/power" {
+ fmt.Fprintln(w, "BAD ZOOT")
+ return
+ }
+ fmt.Fprintln(w, "BAD URL", tmp)
+ // log.Warn("BAD URL =", url, "REPO URL =", repourl)
+ // badurl(w, r.URL.String())
+ // fmt.Fprintln(w, "BAD", tmp)
+}
+
+func main() {
+ log.Println("found log =", versionMap["go.wit.com/log"])
+ http.HandleFunc("/", okHandler)
+ err := http.ListenAndServe(":3000", nil)
+ if err != nil {
+ log.Println("Error starting server:", err)
+ }
+}
+
+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
+}