dock 1.1 KB

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