|
@@ -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)
|
|
|
+}
|