ソースを参照

Загрузить файлы ''

Gr794_Vaa 2 年 前
コミット
a51ca31edf
1 ファイル変更51 行追加0 行削除
  1. 51 0
      laba2.go

+ 51 - 0
laba2.go

@@ -0,0 +1,51 @@
+package main
+
+import (
+	"fmt"
+	"io/ioutil"
+	"log"
+	"net/http"
+	"regexp"
+	"time"
+)
+
+func main() {
+	gugugaga()
+}
+
+func gugugaga() {
+	http.HandleFunc("/ok/", status200)
+	http.HandleFunc("/info/", information)
+	http.HandleFunc("/status/", status)
+	err := http.ListenAndServe(":7070", nil)
+	if err != nil {
+		log.Fatal("ListenAndServer:", err)
+		return
+	}
+
+}
+func status200(w http.ResponseWriter, r *http.Request) {
+	w.Write([]byte("статус 200"))
+}
+
+func information(w http.ResponseWriter, r *http.Request) {
+	w.Write([]byte("группа 792(4)\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)
+
+	ewq := reg.ReplaceAllString(out, ".o.o.")
+	fmt.Fprintf(w, "\n%s", ewq)
+}