Parcourir la source

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

gr792_bad il y a 2 ans
Parent
commit
859ec7bf16
1 fichiers modifiés avec 41 ajouts et 28 suppressions
  1. 41 28
      main.go

+ 41 - 28
main.go

@@ -1,28 +1,41 @@
-package main
-
-import (
-	"fmt"
-	"log"
-	"net/http"
-)
-
-func main() {
-
-	http.HandleFunc("/OK", dvesti)
-	http.HandleFunc("/info", info)
-	err := http.ListenAndServe(":8082", nil)
-	if err != nil {
-		log.Fatal("ListenAndServe: ", err)
-	}
-}
-
-func dvesti(w http.ResponseWriter, r *http.Request) {
-
-	fmt.Fprint(w, "ok")
-	w.WriteHeader(200)
-}
-
-func info(w http.ResponseWriter, r *http.Request) {
-
-	fmt.Fprint(w, "Бердниченко Артем Дмитриевич, группа 792")
-}
+package main
+
+import (
+	"fmt"
+	"log"
+	"net"
+	"net/http"
+	"regexp"
+	"time"
+)
+
+func main() {
+
+	http.HandleFunc("/OK", dvesti)
+	http.HandleFunc("/info", info)
+	http.HandleFunc("/status", status)
+	err := http.ListenAndServe(":8082", nil)
+	if err != nil {
+		log.Fatal("ListenAndServe: ", err)
+	}
+}
+
+func dvesti(w http.ResponseWriter, r *http.Request) {
+
+	fmt.Fprint(w, "ok")
+	w.WriteHeader(200)
+}
+
+func info(w http.ResponseWriter, r *http.Request) {
+
+	fmt.Fprint(w, "Бердниченко Артем Дмитриевич, группа 792")
+}
+
+func status(w http.ResponseWriter, r *http.Request) {
+	time := time.Now()
+	ip, _, _ := net.SplitHostPort(r.RemoteAddr)
+	re := regexp.MustCompile(`[.].*[.]`)
+	fmt.Fprintln(w, re.ReplaceAllString(ip, ".#.#."))
+	fmt.Fprintf(w, "Бердниченко А.Д."+"\n")
+	fmt.Fprintln(w, time.Format("2006-01-02 3:4:5 pm"))
+}