fix(fight): 战斗修改
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/xiaoqidun/qqwry"
|
||||
"github.com/xiaoqidun/qqwry/assets"
|
||||
"os"
|
||||
)
|
||||
|
||||
func init() {
|
||||
qqwry.LoadData(assets.QQWryIpdb)
|
||||
}
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
return
|
||||
}
|
||||
queryIp := os.Args[1]
|
||||
location, err := qqwry.QueryIP(queryIp)
|
||||
if err != nil {
|
||||
fmt.Printf("错误:%v\n", err)
|
||||
return
|
||||
}
|
||||
emptyVal := func(val string) string {
|
||||
if val != "" {
|
||||
return val
|
||||
}
|
||||
return "未知"
|
||||
}
|
||||
fmt.Printf("国家:%s,省份:%s,城市:%s,区县:%s,运营商:%s\n",
|
||||
emptyVal(location.Country),
|
||||
emptyVal(location.Province),
|
||||
emptyVal(location.City),
|
||||
emptyVal(location.District),
|
||||
emptyVal(location.ISP),
|
||||
)
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"github.com/xiaoqidun/qqwry"
|
||||
"github.com/xiaoqidun/qqwry/assets"
|
||||
"net"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type resp struct {
|
||||
Data *qqwry.Location `json:"data"`
|
||||
Success bool `json:"success"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
qqwry.LoadData(assets.QQWryIpdb)
|
||||
}
|
||||
|
||||
func main() {
|
||||
listen := flag.String("listen", "127.0.0.1:80", "http server listen addr")
|
||||
flag.Parse()
|
||||
http.HandleFunc("/ip/", IpAPI)
|
||||
if err := http.ListenAndServe(*listen, nil); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func IpAPI(writer http.ResponseWriter, request *http.Request) {
|
||||
ip := request.URL.Path[4:]
|
||||
if ip == "" {
|
||||
ip, _, _ = net.SplitHostPort(request.RemoteAddr)
|
||||
}
|
||||
response := &resp{}
|
||||
location, err := qqwry.QueryIP(ip)
|
||||
if err != nil {
|
||||
response.Message = err.Error()
|
||||
} else {
|
||||
response.Data = location
|
||||
response.Success = true
|
||||
}
|
||||
b, _ := json.MarshalIndent(response, "", " ")
|
||||
_, _ = writer.Write(b)
|
||||
}
|
||||
Reference in New Issue
Block a user