更新 main.go
parent
cb2fdf2ffd
commit
82e2ba1928
19
main.go
19
main.go
|
|
@ -7,22 +7,31 @@ import (
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
//modules.ImportDatabaseToHex()
|
//modules.ImportDatabaseToHex()
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
//测试用ip地址
|
//测试用ip地址
|
||||||
ip := "103.47.100.182"
|
//ip := "103.47.100.182"
|
||||||
//获取访问浏览器ip
|
//获取访问浏览器ip
|
||||||
//ip := strings.Split(r.RemoteAddr, ":")[0]
|
ip := strings.Split(r.RemoteAddr, ":")[0]
|
||||||
//fmt.Println("客户端IP地址:", ip)
|
//fmt.Println("客户端IP地址:", ip)
|
||||||
|
|
||||||
|
if ip == "" {
|
||||||
|
w.Write([]byte("Invalid IP"))
|
||||||
|
}
|
||||||
|
IP_info = modules.GetIPInformation(ip)
|
||||||
log.Println("客户端ip:", ip)
|
log.Println("客户端ip:", ip)
|
||||||
|
|
||||||
//使用mmdb查询ip
|
//使用mmdb查询ip
|
||||||
//IpIformation := modules.MmdbQueryIP(ip)
|
IpIformation := modules.MmdbQueryIP(ip)
|
||||||
|
|
||||||
//使用MySql查询ip
|
//使用MySql查询ip
|
||||||
dsn := modules.Readconfig()
|
//dsn := modules.Readconfig()
|
||||||
IpIformation := modules.MysqlQuery(ip, dsn)
|
//IpIformation := modules.MysqlQuery(ip, dsn)
|
||||||
|
|
||||||
log.Println("tag:main", IpIformation)
|
log.Println("tag:main", IpIformation)
|
||||||
jsonData, err := json.Marshal(IpIformation)
|
jsonData, err := json.Marshal(IpIformation)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue