beego获取用户ip判断地址
所需package
"encoding/json"
所需第三方插件
阿里云IP地址查询
这个并没有golang的借口提供,我们可以根据他提供的 Python来进行修改
代码如下:
type Data struct{
Area string
Area_id string
City string
City_id string
Country string
Country_id string
County string
County_id string
Ip string
Isp string
Isp_id string
Region string
Region_id string
}
type
Result struct{
Code int
Data Data
}
func (c *
MessageController
) Post(){
host := ""
//链接
path := "/rest/160601/ip/"
appcode := "***************************"
//秘钥,需要申请
querys := ()
//获取用户ip
url := host + path + "?ip=" + querys
request :=
httplib.Get(url)
//beego,httplib get访问
("Authorization", "APPCODE "+appcode)
//请求头
content, _ := ()
//请求结果数据类型
(content)
//打印请求结果如下
obj := Result{}
//转换格式
res := ([]byte(content), &obj)
if res == nil {
(obj)
()
}
}