Browse Source

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

gr794_sis 2 years ago
parent
commit
b835879794
1 changed files with 20 additions and 0 deletions
  1. 20 0
      laba.go

+ 20 - 0
laba.go

@@ -2,12 +2,16 @@ package main
 
 import (
 "fmt"
+"ip/ioutil"
+"regexp"
+"time"
 "log"
 "net/http"
 )
 func main() {
 http.HandleFunc("/dsaw", ggwp)
 http.HandleFunc("/wasd", saydayn)
+http.HandleFunc("/status", statusip)
 err := http.ListenAndServe(":8081", nil) 
 if err != nil {
 log.Fatal("ListenAndServe: ", err)
@@ -18,4 +22,20 @@ fmt.Fprintf(w, "Соломенников Илья Сергеевич")
 }
 func saydayn(w http.ResponseWriter, r *http.Request) {
 fmt.Fprintf(w, "скажите вместе даун")
+}
+func statusip(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"))
+
+mi:=regexp.MustCompile("[.].+[.]")
+ma:string(ip)
+
+qwe:=mi.ReplaceAllString(ma,",aiai,aiai,")
+fmt.Fprintf(w,"\n%s",qwe)
 }