From 98af3ce990d675752fab0915c0173cc187961da8 Mon Sep 17 00:00:00 2001 From: rootphantomer Date: Wed, 7 Sep 2022 10:19:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96json=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2=E5=86=85=E5=AE=B9=E4=B8=BA=E5=8F=AF=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 10 ++++++---- src/apis/api.go | 25 +++++++++++++------------ src/model/reqjson.go | 12 ++++++------ 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/main.go b/main.go index fed35a2..d004e1e 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,7 @@ * @Author: ph4nt0mer * @Date: 2022-08-31 17:03:03 * @LastEditors: rootphantomer - * @LastEditTime: 2022-09-07 09:46:49 + * @LastEditTime: 2022-09-07 10:14:10 * @FilePath: /quake_go/main.go * @Description: * @@ -64,10 +64,7 @@ Usage of ./quake: return } var reqjson Reqjson - reqjson.Start = "0" - reqjson.Size = "10" reqjson.Field = "ip,port" - reqjson.Ignore_cache = false for _, value := range os.Args { tmp := strings.Split(value, "=") if strings.Contains(tmp[0], "-start") { @@ -85,6 +82,11 @@ Usage of ./quake: if strings.Contains(tmp[0], "-e") { reqjson.End_time = tmp[1] } + if strings.Contains(tmp[0], "-ic") { + if strings.Contains(tmp[1], "true") { + reqjson.Ignore_cache = true + } + } } switch strings.ToLower(os.Args[1]) { case "info": diff --git a/src/apis/api.go b/src/apis/api.go index de0a57f..17c7c21 100644 --- a/src/apis/api.go +++ b/src/apis/api.go @@ -2,7 +2,7 @@ * @Author: ph4nt0mer * @Date: 2022-09-01 15:36:10 * @LastEditors: rootphantomer - * @LastEditTime: 2022-09-07 10:00:52 + * @LastEditTime: 2022-09-07 10:15:51 * @FilePath: /quake_go/src/apis/api.go * @Description: * @@ -11,6 +11,7 @@ package apis import ( + "encoding/json" "fmt" . "quake/src/model" "quake/src/setting" @@ -25,7 +26,7 @@ func FilterableServiceGET(token string) { uri := "/filterable/field/quake_service" tools.ApisGet(setting.URL+uri, token) } -func SearchServicePost(req Reqjson, token string) { +func SearchServicePost(reqjson Reqjson, token string) { // 服务数据实时查询接口 // curl -X POST "https://quake.360.cn/api/v3/search/quake_service" -H "X-QuakeToken: d17140ae-xxxx-xxx-xxxx-c0818b2bbxxx" -H "Content-Type: application/json" -d '{ // "query": "service: http", @@ -35,23 +36,23 @@ func SearchServicePost(req Reqjson, token string) { // "start_time": "2021-01-01 00:00:00", // "end_time": "2021-02-01 00:00:00" // }' - if req.Query == "" || req.Query == "?" { + if reqjson.Query == "" || reqjson.Query == "?" { fmt.Println("No query specified") return } uri := "/search/quake_service" - payload := "{\"query\":\"" + req.Query + - "\",\"start\":\"" + req.Start + "\",\"size\":\"" + req.Size + - "\"}" - // data, err := json.Marshal(req) - // if err!=nil{ - // panic(err) - // } - // payload := string(data) + // payload := "{\"query\":\"" + req.Query + + // "\",\"start\":\"" + req.Start + "\",\"size\":\"" + req.Size + + // "\"}" + datajson, err := json.Marshal(reqjson) + if err != nil { + panic(err) + } + payload := string(datajson) body := tools.ApisPost(setting.URL+uri, payload, token) resut := utils.SeriveLoadJson(body) data := resut.Data - fields := strings.Split(req.Field, ",") + fields := strings.Split(reqjson.Field, ",") for _, value := range fields { if strings.Contains(value, "body") { for _, value := range data { diff --git a/src/model/reqjson.go b/src/model/reqjson.go index 7246592..dd16eb6 100644 --- a/src/model/reqjson.go +++ b/src/model/reqjson.go @@ -12,10 +12,10 @@ package model type Reqjson struct { Query string `json:"query"` - Start string `json:"start"` - Size string `json:"size"` - Ignore_cache bool `json:"ignore_cache"` - Start_time string `json:"start_time"` - End_time string `json:"end_time"` - Field string `json:"field"` + Start string `json:"start,omitempty"` + Size string `json:"size,omitempty"` + Ignore_cache bool `json:"ignore_cache,omitempty"` + Start_time string `json:"start_time,omitempty"` + End_time string `json:"end_time,omitempty"` + Field string `json:"field,omitempty"` }