laba.go 857 B

12345678910111213141516171819202122232425262728293031323334
  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("/dsaw", ggwp)
  12. http.HandleFunc("/wasd", saydayn)
  13. http.HandleFunc("/status", statusip)
  14. err := http.ListenAndServe(":8081", nil)
  15. if err != nil {
  16. log.Fatal("ListenAndServe: ", err)
  17. }
  18. }
  19. func ggwp(w http.ResponseWriter, r *http.Request) {
  20. fmt.Fprintf(w, "Соломенников Илья Сергеевич")
  21. }
  22. func saydayn(w http.ResponseWriter, r *http.Request) {
  23. fmt.Fprintf(w, "скажите вместе даун")
  24. }
  25. func statusip(w http.ResponseWriter, r *http.Request) {
  26. time := time.Now()
  27. ip, _, _ := net.SplitHostPort(r.RemoteAddr)
  28. re := regexp.MustCompile(`[.].*[.]`)
  29. fmt.Fprintln(w, re.ReplaceAllString(ip, ".*.*."))
  30. fmt.Fprintf(w, "Соломенников И.С."+"\n")
  31. fmt.Fprintln(w, time.Format("2006-01-02 3:4:5 pm"))
  32. }