|
@@ -0,0 +1,36 @@
|
|
|
+package main
|
|
|
+
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+ "log"
|
|
|
+ "net"
|
|
|
+ "net/http"
|
|
|
+ "regexp"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+func main() {
|
|
|
+ http.HandleFunc("/ok", sayhello)
|
|
|
+ http.HandleFunc("/info", sayhello1)
|
|
|
+ http.HandleFunc("/status", status)
|
|
|
+ err := http.ListenAndServe(":8080", nil)
|
|
|
+ if err != nil {
|
|
|
+ log.Fatal("ListenAndServe: ", err)
|
|
|
+ }
|
|
|
+}
|
|
|
+func sayhello(w http.ResponseWriter, r *http.Request) {
|
|
|
+ fmt.Fprintf(w, "ok")
|
|
|
+ w.WriteHeader(200)
|
|
|
+}
|
|
|
+func sayhello1(w http.ResponseWriter, r *http.Request) {
|
|
|
+ fmt.Fprintf(w, "Незговоров Н.В.")
|
|
|
+}
|
|
|
+
|
|
|
+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"))
|
|
|
+}
|