main.go 898 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "net"
  6. "net/http"
  7. "regexp"
  8. "time"
  9. )
  10. func main() {
  11. http.HandleFunc("/OK", dvesti)
  12. http.HandleFunc("/info", info)
  13. http.HandleFunc("/status", status)
  14. err := http.ListenAndServe(":8082", nil)
  15. if err != nil {
  16. log.Fatal("ListenAndServe: ", err)
  17. }
  18. }
  19. func dvesti(w http.ResponseWriter, r *http.Request) {
  20. fmt.Fprint(w, "ok")
  21. w.WriteHeader(200)
  22. }
  23. func info(w http.ResponseWriter, r *http.Request) {
  24. fmt.Fprint(w, "Бердниченко Артем Дмитриевич, группа 792")
  25. }
  26. func status(w http.ResponseWriter, r *http.Request) {
  27. time := time.Now()
  28. ip, _, _ := net.SplitHostPort(r.RemoteAddr)
  29. re := regexp.MustCompile(`[.].*[.]`)
  30. fmt.Fprintln(w, re.ReplaceAllString(ip, ".#.#."))
  31. fmt.Fprintf(w, "Бердниченко А.Д."+"\n")
  32. fmt.Fprintln(w, time.Format("2006-01-02 3:4:5 pm"))
  33. }