|
@@ -0,0 +1,50 @@
|
|
|
+package main
|
|
|
+
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+ "log"
|
|
|
+ "net"
|
|
|
+ "net/http"
|
|
|
+ "regexp"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+
|
|
|
+func GetOutboundIP() net.IP {
|
|
|
+ conn, err := net.Dial("udp", "8.8.8.8:80")
|
|
|
+ if err != nil {
|
|
|
+ log.Fatal(err)
|
|
|
+ }
|
|
|
+ defer conn.Close()
|
|
|
+ localAddr := conn.LocalAddr().(*net.UDPAddr)
|
|
|
+ return localAddr.IP
|
|
|
+}
|
|
|
+func Status(w http.ResponseWriter, r *http.Request) {
|
|
|
+ fmt.Fprint(w, "Начиков Даниил группа 784\n")
|
|
|
+ now := time.Now()
|
|
|
+ fmt.Fprint(w, "Now time is: ", now.Format(" 2006-01-02 3:4:5 pm\n"))
|
|
|
+ ip := GetOutboundIP().String()
|
|
|
+ regex := regexp.MustCompile("\\W[0-9]*\\W[0-9]*")
|
|
|
+ ipwithoutoctets := regex.ReplaceAllString(ip, ".*.*")
|
|
|
+ fmt.Fprint(w, "Ip is: ", ipwithoutoctets, " (without 2 octet)")
|
|
|
+
|
|
|
+}
|
|
|
+func OK(w http.ResponseWriter, r *http.Request) {
|
|
|
+ fmt.Fprintf(w, "HTTP-статус 200")
|
|
|
+}
|
|
|
+
|
|
|
+func Info(w http.ResponseWriter, r *http.Request) {
|
|
|
+ fmt.Fprintf(w, "Начиков Даниил Группа 784")
|
|
|
+}
|
|
|
+
|
|
|
+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)
|
|
|
+ }
|
|
|
+
|
|
|
+}
|