diff --git a/db/db.go b/db/db.go index efac25d..3f92f84 100644 --- a/db/db.go +++ b/db/db.go @@ -11,8 +11,8 @@ import ( func ConnectDb() *sql.DB { - //db, _ := sql.Open("mysql", "root:Skyinno251,@tcp(47.242.184.139:3306)/goftp") - db, _ := sql.Open("mysql", "root:Skyinno251,@tcp(127.0.0.1:3306)/goftp") + db, _ := sql.Open("mysql", "root:Skyinno251,@tcp(47.242.184.139:3306)/goftp") + //db, _ := sql.Open("mysql", "root:Skyinno251,@tcp(127.0.0.1:3306)/goftp") //if err != nil { // fmt.Println(err.Error()) // return diff --git a/httpbin/handlers.go b/httpbin/handlers.go index cc5e58e..11f67ff 100644 --- a/httpbin/handlers.go +++ b/httpbin/handlers.go @@ -128,6 +128,36 @@ func (h *HTTPBin) IP(w http.ResponseWriter, r *http.Request) { writeJSON(w, body, http.StatusOK) } +func (h *HTTPBin) IP1(w http.ResponseWriter, r *http.Request) { + ret := models.Ret{Data: []string{}} + ret.Ret = "ok" + ret.Ip = "" + origin := getOrigin(r) + if len(origin) > 0 { + ipArray := strings.Split(origin, ":") + if len(ipArray) > 1 { + ret.Ip = ipArray[0] + } + } + body, _ := json.Marshal(ret) + writeJSON(w, body, http.StatusOK) +} + +func (h *HTTPBin) IP2(w http.ResponseWriter, r *http.Request) { + ret := models.Ret{Data: []string{}} + ret.Ret = "ok" + ret.Ip = "" + origin := getOrigin(r) + if len(origin) > 0 { + ipArray := strings.Split(origin, ":") + if len(ipArray) > 1 { + ret.Ip = ipArray[0] + } + } + body, _ := json.Marshal(ret) + writeJSON(w, body, http.StatusOK) +} + func (h *HTTPBin) IP10(w http.ResponseWriter, r *http.Request) { cmip := models.QueryIp10() ret := models.Ret{Data: []string{}} diff --git a/httpbin/httpbin.go b/httpbin/httpbin.go index c04dc4b..b1596e0 100644 --- a/httpbin/httpbin.go +++ b/httpbin/httpbin.go @@ -131,6 +131,8 @@ func (h *HTTPBin) Handler() http.Handler { mux.HandleFunc("/delete", methods(h.RequestWithBody, "DELETE")) mux.HandleFunc("/ip", h.IP) + mux.HandleFunc("/ip1", h.IP1) + mux.HandleFunc("/ip2", h.IP2) mux.HandleFunc("/ip10", h.IP10) mux.HandleFunc("/ip20", h.IP20) mux.HandleFunc("/ssh", h.Ssh)