laba.go 895 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package main
  2. import (
  3. "fmt"
  4. "ip/ioutil"
  5. "regexp"
  6. "time"
  7. "log"
  8. "net/http"
  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. res,_:=http.Get("https://api/ipify.org/")
  27. ip,err:=ioutil.ReadAll(res.Body)
  28. if err !=nil {
  29. return
  30. }
  31. fmt.Fprintf(w,"%s\n",ip)
  32. today:= time.Now()
  33. fmt.Fprintf(w,today.Format("2006-01-02 3:4:5"))
  34. mi:=regexp.MustCompile("[.].+[.]")
  35. ma:string(ip)
  36. qwe:=mi.ReplaceAllString(ma,",aiai,aiai,")
  37. fmt.Fprintf(w,"\n%s",qwe)
  38. }