main.go 936 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "net/http"
  6. "strings"
  7. "time"
  8. )
  9. func main() {
  10. http.HandleFunc("/", slash)
  11. http.HandleFunc("/ok", ok)
  12. http.HandleFunc("/info", info)
  13. http.HandleFunc("/status", status)
  14. err := http.ListenAndServe("localhost:0808", nil)
  15. if err != nil {
  16. log.Fatal("ListenAndServe: ", err)
  17. }
  18. }
  19. func slash (w http.ResponseWriter,r *http.Request) {
  20. fmt.Fprint(w,"it alive")
  21. }
  22. func ok (w http.ResponseWriter,r *http.Request) {
  23. w.WriteHeader(http.StatusOK)
  24. fmt.Fprint(w,"http status ok ")
  25. }
  26. func info (w http.ResponseWriter,r *http.Request) {
  27. fmt.Fprint(w,"LI Vladislave♂")
  28. }
  29. func status (w http.ResponseWriter,r *http.Request) {
  30. var remoteIp = r.RemoteAddr
  31. var splitIp = strings.Split(remoteIp, ".")
  32. var fmtIP = fmt.Sprint(splitIp[0], ".x./.", strings.Split(splitIp[3], ":")[0])
  33. var fmtDate = time.Now().Format("2006-01-02 3:4:5 ")
  34. fmt.Fprintf(w,"made the Vlad\n")
  35. fmt.Fprintf(w, fmtDate + "\n")
  36. fmt.Fprintf(w, fmtIP)
  37. }