Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
优化json字符串内容为可选项
Browse files Browse the repository at this point in the history
  • Loading branch information
rootphantomer committed Sep 7, 2022
1 parent 2c624c8 commit 98af3ce
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
10 changes: 6 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
*
Expand Down Expand Up @@ -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") {
Expand All @@ -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":
Expand Down
25 changes: 13 additions & 12 deletions src/apis/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
*
Expand All @@ -11,6 +11,7 @@
package apis

import (
"encoding/json"
"fmt"
. "quake/src/model"
"quake/src/setting"
Expand All @@ -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",
Expand All @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions src/model/reqjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

0 comments on commit 98af3ce

Please sign in to comment.