Your Name před 2 roky
revize
cc0e6ec0ee
2 změnil soubory, kde provedl 44 přidání a 0 odebrání
  1. 4 0
      Dockerfile
  2. 40 0
      main.go

+ 4 - 0
Dockerfile

@@ -0,0 +1,4 @@
+FROM golang:alpine
+WORKDIR /opt/site
+COPY . /opt/site/
+CMD ["go", "run", "main.go"]

+ 40 - 0
main.go

@@ -0,0 +1,40 @@
+package main
+import(
+"fmt"
+"log"
+"net/http"
+"net"
+"regexp"
+"time"
+
+)
+func main() {
+http.HandleFunc("/Info", info)
+http.HandleFunc("/Ok", ok)
+http.HandleFunc("/status", status)
+err := http.ListenAndServe(":8080",nil)
+if err != nil {
+log.Fatal("ListenAndServe: ", err)
+ }
+
+}
+
+func ok(w http.ResponseWriter, r *http.Request){
+fmt.Fprintf(w, "http status: 200")
+}
+
+func info(w http.ResponseWriter, r *http.Request){
+fmt.Fprintf(w, "Привет, студент группы 792, Мотрев Никита Дмитриевич ")
+}
+
+func status(w http.ResponseWriter, r *http.Request){
+dt := time.Now()
+ip,_,_:=net.SplitHostPort(r.RemoteAddr)
+res := regexp.MustCompile(`[.]\d[.]\d[.]`)
+fmt.Fprintln(w,res.ReplaceAllString(ip,".*.*."))
+fmt.Fprintf(w,"Мотрев Никита Дмитриевич\n")
+fmt.Fprintf(w, dt.Format("2006-01-02 3:4:5 pm"))
+}
+
+
+