mirror of
https://github.com/nxtrace/NTrace-core.git
synced 2025-08-12 06:26:39 +00:00
provide ability to override baseurl of APIs
This commit is contained in:
@@ -14,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
func IPApiCom(ip string, timeout time.Duration, _ string, _ bool) (*IPGeoData, error) {
|
||||
url := "http://ip-api.com/json/" + ip + "?fields=status,message,country,regionName,city,isp,district,as,lat,lon"
|
||||
url := token.BaseOrDefault("http://ip-api.com/json/") + ip + "?fields=status,message,country,regionName,city,isp,district,as,lat,lon"
|
||||
client := &http.Client{
|
||||
// 2 秒超时
|
||||
Timeout: timeout,
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func IPInfo(ip string, timeout time.Duration, _ string, _ bool) (*IPGeoData, error) {
|
||||
url := "http://ipinfo.io/" + ip + "?token=" + token.ipinfo
|
||||
url := token.BaseOrDefault("http://ipinfo.io/") + ip + "?token=" + token.ipinfo
|
||||
client := &http.Client{
|
||||
// 2 秒超时
|
||||
Timeout: timeout,
|
||||
|
||||
@@ -13,7 +13,7 @@ func IPInSight(ip string, timeout time.Duration, _ string, _ bool) (*IPGeoData,
|
||||
// 2 秒超时
|
||||
Timeout: timeout,
|
||||
}
|
||||
resp, err := client.Get("https://api.ipinsight.io/ip/" + ip + "?token=" + token.ipinsight)
|
||||
resp, err := client.Get(token.BaseOrDefault("https://api.ipinsight.io/ip/") + ip + "?token=" + token.ipinsight)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func IPSB(ip string, timeout time.Duration, _ string, _ bool) (*IPGeoData, error) {
|
||||
url := "https://api.ip.sb/geoip/" + ip
|
||||
url := token.BaseOrDefault("https://api.ip.sb/geoip/") + ip
|
||||
client := &http.Client{
|
||||
// 2 秒超时
|
||||
Timeout: timeout,
|
||||
|
||||
@@ -6,10 +6,19 @@ type tokenData struct {
|
||||
ipinsight string
|
||||
ipinfo string
|
||||
ipleo string
|
||||
baseUrl string
|
||||
}
|
||||
|
||||
func (t *tokenData) BaseOrDefault(def string) string {
|
||||
if t.baseUrl == "" {
|
||||
return def
|
||||
}
|
||||
return t.baseUrl
|
||||
}
|
||||
|
||||
var token = tokenData{
|
||||
ipinsight: util.GetenvDefault("NEXTTRACE_IPINSIGHT_TOKEN", ""),
|
||||
ipinfo: util.GetenvDefault("NEXTTRACE_IPINFO_TOKEN", ""),
|
||||
baseUrl: util.GetenvDefault("NEXTTRACE_IPAPI_BASE", ""),
|
||||
ipleo: "NextTraceDemo",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user