2024-10-06 09:48:35 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
|
|
|
|
2024-10-06 10:28:16 -05:00
|
|
|
// var accessf, clientf *os.File
|
2024-10-06 09:48:35 -05:00
|
|
|
|
2024-10-06 10:28:16 -05:00
|
|
|
// var repoMap map[string]string
|
|
|
|
// var versionMap map[string]string
|
|
|
|
// var keysSorted []string
|
2024-10-06 09:48:35 -05:00
|
|
|
|
|
|
|
// 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]
|
|
|
|
|
2024-10-06 10:28:16 -05:00
|
|
|
if tmp == "/powersource" {
|
|
|
|
fmt.Fprintln(w, "Utility Power")
|
2024-10-06 09:48:35 -05:00
|
|
|
return
|
|
|
|
}
|
2024-10-06 10:28:16 -05:00
|
|
|
if tmp == "/lastoutage" {
|
|
|
|
fmt.Fprintln(w, "Blackout at 2024/09/25 20:21:57 for 33 sec.")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fmt.Fprintln(w, "UNKNOWN URL:", tmp)
|
2024-10-06 09:48:35 -05:00
|
|
|
// log.Warn("BAD URL =", url, "REPO URL =", repourl)
|
|
|
|
// badurl(w, r.URL.String())
|
|
|
|
// fmt.Fprintln(w, "BAD", tmp)
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
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
|
|
|
|
}
|