test.go 878 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "net"
  6. "net/http"
  7. "regexp"
  8. "time"
  9. )
  10. func main() {
  11. http.Handle("/", http.FileServer(http.Dir("./static")))
  12. http.HandleFunc("/ok", sayhello)
  13. http.HandleFunc("/info", sayhello1)
  14. http.HandleFunc("/status", status)
  15. err := http.ListenAndServe(":8080", nil)
  16. if err != nil {
  17. log.Fatal("ListenAndServe: ", err)
  18. }
  19. }
  20. func sayhello(w http.ResponseWriter, r *http.Request) {
  21. fmt.Fprintf(w, "ok")
  22. w.WriteHeader(200)
  23. }
  24. func sayhello1(w http.ResponseWriter, r *http.Request) {
  25. fmt.Fprintf(w, "Незговоров Н.В.")
  26. }
  27. func status(w http.ResponseWriter, r *http.Request) {
  28. time := time.Now()
  29. ip, _, _ := net.SplitHostPort(r.RemoteAddr)
  30. re := regexp.MustCompile(`[.].*[.]`)
  31. fmt.Fprintln(w, re.ReplaceAllString(ip, ".*.*."))
  32. fmt.Fprintf(w, "Незговоров Н.В."+"\n")
  33. fmt.Fprintln(w, time.Format("2006-01-02 3:4:5 pm"))
  34. }