|
@@ -1,41 +1,34 @@
|
|
package main
|
|
package main
|
|
|
|
|
|
import (
|
|
import (
|
|
-"fmt"
|
|
|
|
-"ip/ioutil"
|
|
|
|
-"regexp"
|
|
|
|
-"time"
|
|
|
|
-"log"
|
|
|
|
-"net/http"
|
|
|
|
|
|
+ "fmt"
|
|
|
|
+ "log"
|
|
|
|
+ "net"
|
|
|
|
+ "net/http"
|
|
|
|
+ "regexp"
|
|
|
|
+ "time"
|
|
)
|
|
)
|
|
|
|
+
|
|
func main() {
|
|
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)
|
|
|
|
-}
|
|
|
|
|
|
+ http.HandleFunc("/dsaw", ggwp)
|
|
|
|
+ http.HandleFunc("/wasd", saydayn)
|
|
|
|
+ http.HandleFunc("/status", statusip)
|
|
|
|
+ err := http.ListenAndServe(":8081", nil)
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Fatal("ListenAndServe: ", err)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
func ggwp(w http.ResponseWriter, r *http.Request) {
|
|
func ggwp(w http.ResponseWriter, r *http.Request) {
|
|
-fmt.Fprintf(w, "Соломенников Илья Сергеевич")
|
|
|
|
|
|
+ fmt.Fprintf(w, "Соломенников Илья Сергеевич")
|
|
}
|
|
}
|
|
func saydayn(w http.ResponseWriter, r *http.Request) {
|
|
func saydayn(w http.ResponseWriter, r *http.Request) {
|
|
-fmt.Fprintf(w, "скажите вместе даун")
|
|
|
|
|
|
+ fmt.Fprintf(w, "скажите вместе даун")
|
|
}
|
|
}
|
|
func statusip(w http.ResponseWriter, r *http.Request) {
|
|
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
|
|
|
|
|
|
+ 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"))
|
|
}
|
|
}
|
|
-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)
|
|
|
|
-}
|
|
|