package main import ( "fmt" "net/http" "strings" "time" "go.wit.com/log" ) // var accessf, clientf *os.File // var repoMap map[string]string // var versionMap map[string]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) { var tmp 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 == "/powersource" { fmt.Fprintln(w, "Utility Power") return } if tmp == "/lastoutage" { fmt.Fprintln(w, "Blackout at 2024/09/25 20:21:57 for 33 sec.") return } fmt.Fprintln(w, "UNKNOWN URL:", tmp) // log.Warn("BAD URL =", url, "REPO URL =", repourl) // badurl(w, r.URL.String()) // fmt.Fprintln(w, "BAD", tmp) } func main() { var hostname string = args.Hostname if hostname == "" { hostname = "localhost" } log.Info("curl http://" + hostname + ":3000/powersource # shows if your power grid is up") log.Info("curl http://" + hostname + ":3000/lastoutage # shows the last time your power grid went down") log.Info("hostname =", hostname) 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 }