feat: 添加是否获取地理位置的开关。
This commit is contained in:
parent
642904c2b4
commit
05bd2702ef
@ -57,3 +57,5 @@ settings:
|
||||
ssl:
|
||||
key: keystring
|
||||
pem: temp/pem.pem
|
||||
public:
|
||||
isLocation: 0
|
||||
|
@ -57,3 +57,5 @@ settings:
|
||||
ssl:
|
||||
key: keystring
|
||||
pem: temp/pem.pem
|
||||
public:
|
||||
isLocation: 0
|
||||
|
10
tools/ip.go
10
tools/ip.go
@ -5,20 +5,22 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func GetLocation(ip string) string {
|
||||
var address = "已关闭位置获取"
|
||||
if viper.GetBool("settings.public.isLocation") {
|
||||
if ip == "127.0.0.1" || ip == "localhost" {
|
||||
return "内部IP"
|
||||
}
|
||||
resp, err := http.Get("https://restapi.amap.com/v3/ip?ip=" + ip + "&key=3fabc36c20379fbb9300c79b19d5d05e")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
s, err := ioutil.ReadAll(resp.Body)
|
||||
fmt.Printf(string(s))
|
||||
|
||||
m := make(map[string]string)
|
||||
|
||||
@ -29,5 +31,7 @@ func GetLocation(ip string) string {
|
||||
if m["province"] == "" {
|
||||
return "未知位置"
|
||||
}
|
||||
return m["province"] + "-" + m["city"]
|
||||
address = m["province"] + "-" + m["city"]
|
||||
}
|
||||
return address
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user