1
无
This commit is contained in:
71
main.go
Normal file
71
main.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"checkIP/modules"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
//func main() {
|
||||
// //modules.ImportDatabaseToHex()
|
||||
// http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
// //测试用ip地址
|
||||
// ip := "125.71.133.170"
|
||||
// //获取访问浏览器ip
|
||||
// //ip := strings.Split(r.RemoteAddr, ":")[0]
|
||||
// //fmt.Println("客户端IP地址:", ip)
|
||||
// log.Println("客户端ip:", ip)
|
||||
// //使用mmdb查询ip
|
||||
// IpIformation := modules.MmdbQueryIP(ip)
|
||||
// //使用MySql查询ip
|
||||
//
|
||||
// log.Println(IpIformation)
|
||||
// jsonData, err := json.Marshal(IpIformation)
|
||||
// if err != nil {
|
||||
// fmt.Println("JSON 序列化失败:", err)
|
||||
// return
|
||||
// }
|
||||
// // 设置响应的 Content-Type 为 application/json
|
||||
// w.Header().Set("Content-Type", "application/json")
|
||||
// // 返回 JSON 数据
|
||||
// print(jsonData)
|
||||
// w.Write(jsonData)
|
||||
// })
|
||||
// http.ListenAndServe(":8341", nil)
|
||||
//}
|
||||
|
||||
//func main() {
|
||||
// modules.ImportLocation_zhCN()
|
||||
// modules.ImportLocation_en()
|
||||
//}
|
||||
|
||||
func main() {
|
||||
//modules.ImportDatabaseToHex()
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
//测试用ip地址
|
||||
ip := "103.47.100.182"
|
||||
//获取访问浏览器ip
|
||||
//ip := strings.Split(r.RemoteAddr, ":")[0]
|
||||
//fmt.Println("客户端IP地址:", ip)
|
||||
log.Println("客户端ip:", ip)
|
||||
//使用mmdb查询ip
|
||||
//IpIformation := modules.MmdbQueryIP(ip)
|
||||
//使用MySql查询ip
|
||||
IpIformation := modules.MysqlQuery(ip)
|
||||
log.Println("tag:main", IpIformation)
|
||||
jsonData, err := json.Marshal(IpIformation)
|
||||
if err != nil {
|
||||
fmt.Println("JSON 序列化失败:", err)
|
||||
return
|
||||
}
|
||||
// 设置响应的 Content-Type 为 application/json
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
// 返回 JSON 数据
|
||||
//log.Println(jsonData)
|
||||
w.Write(jsonData)
|
||||
})
|
||||
http.ListenAndServe(":8341", nil)
|
||||
}
|
||||
Reference in New Issue
Block a user