Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请教一下调整输出JSON的具体格式 #5

Open
missyoyo opened this issue Mar 6, 2020 · 3 comments
Open

请教一下调整输出JSON的具体格式 #5

missyoyo opened this issue Mar 6, 2020 · 3 comments

Comments

@missyoyo
Copy link

missyoyo commented Mar 6, 2020

作者你好,我最近测试了你的API,感觉总体来说非常好,不过你的API输出格式中JSON包含了本身输入的IP地址做为字段,这样在解析的时候会生成动态字段名,举个例子,如果我输入114.114.114.114,
http://127.0.0.1:2060/?ip=114.114.114.114
得到的结果是:
{"114.114.114.114":{"ip":"114.114.114.114","country":"江苏省南京市","area":"南京信风网络科技有限公司GreatbitDNS服务器"}}
进行解析后得到结果:
图片
请教一下源代码中的源个部分能做一下小调整,使用输出结果只保留country和areap字段
例如如下简单的输出结果:
{
"ip": "114.114.114.114",
"country": "江苏省南京市",
"area": "南京信风网络科技有限公司GreatbitDNS服务器"
}
非常感谢。

@aniu-lee
Copy link

aniu-lee commented Mar 9, 2020

自己改呗。

main.go

`
func findIP(w http.ResponseWriter, r *http.Request) {

res := utils.NewResponse(w, r)

ip := r.Form.Get("ip")

if ip == "" {
	res.ReturnError(200, 1, "请填写 IP 地址")
	return
}

ips := strings.Split(ip, ",")[0]

qqWry := utils.NewQQwry()

rs := utils.ResultQQwry{}
//if len(ips) > 0 {
//	for _, v := range ips {
//		rs[v] = qqWry.Find(v)
//	}
//}
rs = qqWry.Find(ips)
if (rs.Area == "" && rs.Country == "") {
	res.ReturnError(200, 1, "暂无数据,或者ip地址有误")
	return
}
res.ReturnSuccess(rs)

}
`

@missyoyo
Copy link
Author

missyoyo commented Mar 9, 2020 via email

@aniu-lee
Copy link

好的,太感谢了,请问你经常写类似的程序吗

------------------ 原始邮件 ------------------ 发件人: "aniu-lee"<[email protected]>; 发送时间: 2020年3月9日(星期一) 中午11:31 收件人: "freshcn/qqwry"<[email protected]>; 抄送: ""<[email protected]>;"Author"<[email protected]>; 主题: Re: [freshcn/qqwry] 请教一下调整输出JSON的具体格式 (#5) 自己改呗。 main.go func findIP(w http.ResponseWriter, r *http.Request) { res := utils.NewResponse(w, r) ip := r.Form.Get("ip") if ip == "" { res.ReturnError(200, 1, "请填写 IP 地址") return } ips := strings.Split(ip, ",")[0] qqWry := utils.NewQQwry() rs := utils.ResultQQwry{} //if len(ips) &gt; 0 { // for _, v := range ips { // rs[v] = qqWry.Find(v) // } //} rs = qqWry.Find(ips) if (rs.Area == "" &amp;&amp; rs.Country == "") { res.ReturnError(200, 1, "暂无数据,或者ip地址有误") return } res.ReturnSuccess(rs) } — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

哈哈,我是写后台的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants