laba2.go 990 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package main
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "log"
  6. "net/http"
  7. "regexp"
  8. "time"
  9. )
  10. func main() {
  11. gugugaga()
  12. }
  13. func gugugaga() {
  14. http.HandleFunc("/ok/", status200)
  15. http.HandleFunc("/info/", information)
  16. http.HandleFunc("/status/", status)
  17. err := http.ListenAndServe(":7070", nil)
  18. if err != nil {
  19. log.Fatal("ListenAndServer:", err)
  20. return
  21. }
  22. }
  23. func status200(w http.ResponseWriter, r *http.Request) {
  24. w.Write([]byte("статус 200"))
  25. }
  26. func information(w http.ResponseWriter, r *http.Request) {
  27. w.Write([]byte("группа 792(4)\n Варламов Алексей"))
  28. }
  29. func status(w http.ResponseWriter, r *http.Request) {
  30. res, _ := http.Get("https://api.ipify.org/")
  31. ip, err := ioutil.ReadAll(res.Body)
  32. if err != nil {
  33. return
  34. }
  35. fmt.Fprintf(w, "%s\n", ip)
  36. today := time.Now()
  37. fmt.Fprintf(w, today.Format("2006-01-02 3:4:5 pm"))
  38. reg := regexp.MustCompile("[.].+[.]")
  39. out := string(ip)
  40. ewq := reg.ReplaceAllString(out, ".o.o.")
  41. fmt.Fprintf(w, "\n%s", ewq)
  42. }