main.go 850 B

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