This commit is contained in:
Lain Iwakura 2025-07-12 14:19:20 +03:00
parent 39504529d2
commit b30877fc17
No known key found for this signature in database
GPG Key ID: C7C18257F2ADC6F8

25
main.go
View File

@ -93,6 +93,30 @@ func wsHandler(w http.ResponseWriter, r *http.Request) {
} }
} }
func statusHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.Header().Set("Server", "0BSD_FOR_EVERYONE")
openbsdBirth := time.Date(1995, 10, 1, 0, 0, 0, 0, time.UTC)
now := time.Now()
duration := now.Sub(openbsdBirth)
years := int(duration.Hours() / 8760)
months := int((duration.Hours() - float64(years*8760)) / 730)
weeks := int((duration.Hours() - float64(years*8760) - float64(months*730)) / 168)
hours := int(duration.Hours() - float64(years*8760) - float64(months*730) - float64(weeks*168))
minutes := int(duration.Minutes()) % 60
seconds := int(duration.Seconds()) % 60
milliseconds := int(duration.Milliseconds()) % 1000
nanoseconds := int(duration.Nanoseconds()) % 1000000
status := fmt.Sprintf("OpenBSD uptime: %d:%d:%d:%d:%d:%d:%d:%d\nTimestamp: %d",
years, months, weeks, hours, minutes, seconds, milliseconds, nanoseconds,
now.Unix())
fmt.Fprint(w, status)
}
func handler(w http.ResponseWriter, r *http.Request) { func handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8") w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.Header().Set("Server", "0BSD_FOR_EVERYONE") w.Header().Set("Server", "0BSD_FOR_EVERYONE")
@ -173,6 +197,7 @@ func main() {
mux := http.NewServeMux() mux := http.NewServeMux()
mux.HandleFunc("/", handler) mux.HandleFunc("/", handler)
mux.HandleFunc("/ws", wsHandler) mux.HandleFunc("/ws", wsHandler)
mux.HandleFunc("/status", statusHandler)
server := &http.Server{ server := &http.Server{
Addr: ":" + p, Addr: ":" + p,