gr794_asr 2 years ago
commit
14595a1e65
2 changed files with 50 additions and 0 deletions
  1. 6 0
      dockerfile
  2. 44 0
      laba3.go

+ 6 - 0
dockerfile

@@ -0,0 +1,6 @@
+FROM golang:onbuild
+WORKDIR ./lab
+COPY ./ ./
+RUN go build -o laba3 .
+EXPOSE 8000
+ENTRYPOINT ["./laba3"]

+ 44 - 0
laba3.go

@@ -0,0 +1,44 @@
+package main
+
+import (
+	"fmt"
+	"io/ioutil"
+	"log"
+	"net/http"
+	"regexp"
+	"time"
+)
+
+func main() {
+	http.HandleFunc("/ok/", ok)
+	http.HandleFunc("/info/", info)
+	http.HandleFunc("/status/", status)
+	err := http.ListenAndServe(":8080", nil)
+	if err != nil {
+		log.Fatal("ListenAndServer:", err)
+		return
+	}
+}
+
+func ok(w http.ResponseWriter, r *http.Request) {
+	fmt.Fprint(w, "ok")
+}
+func info(w http.ResponseWriter, r *http.Request) {
+	fmt.Fprint(w, "группа 792\n Антонов Сергей")
+}
+
+func status(w http.ResponseWriter, r *http.Request) {
+	res, _ := http.Get("https://api.ipify.org/")
+	ip, err := ioutil.ReadAll(res.Body)
+	if err != nil {
+		return
+	}
+	fmt.Fprintf(w, "%s\n", ip)
+	today := time.Now()
+	fmt.Fprintf(w, today.Format("2006-01-02 3:4:5 pm"))
+	reg := regexp.MustCompile("[.].+[.]")
+	out := string(ip)
+
+	qqq := reg.ReplaceAllString(out, ".o.o.")
+	fmt.Fprintf(w, "\n%s", qqq)
+}