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

Commit

Permalink
Merge pull request #1 from rootphantomer/dev
Browse files Browse the repository at this point in the history
v1.1
  • Loading branch information
rootphantomer authored Sep 6, 2022
2 parents cd79e09 + 9f8cd4d commit ce4f086
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 42 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode/
quake_go
quake
quake
config.yaml
24 changes: 10 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: ph4nt0mer
* @Date: 2022-09-01 18:39:52
* @LastEditors: ph4nt0mer
* @LastEditTime: 2022-09-02 15:51:29
* @LastEditTime: 2022-09-06 11:29:48
* @FilePath: /quake_go/README.md
* @Description:
*
Expand All @@ -29,7 +29,13 @@ rust 项目代码 移步这里——https://github.com/360quake/quake_rs/

## 更新日志

- 2022-09-06 v1.1:

- 简化参数传参格式
- 将 token 固化在当前目录

- 2022-09-01 v1.0:

- 新增 info 接口功能
- 新增 service 接口功能

Expand All @@ -38,17 +44,7 @@ rust 项目代码 移步这里——https://github.com/360quake/quake_rs/
```bash
Starting Quake Cli...
example:
./quake -token=<token> -model=<model> -query=<query>

Usage of ./quake_go:
-model string
model String value
-query string
query String value
-size string
size String value (default "10")
-start string
start String value (default "0")
-token string
token Sting value
./quake init <token>
./quake info
./quake query port:443
```
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module quake

go 1.19

require gopkg.in/yaml.v2 v2.4.0
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
62 changes: 35 additions & 27 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,50 @@ import (
"fmt"
"os"
"quake/src/apis"
"quake/src/utils"
"strings"
)

func main() {
Init()
var model, token, query, start, size string
flag.StringVar(&size, "size", "10", "size String value")
flag.StringVar(&start, "start", "0", "start String value")
flag.StringVar(&query, "query", "", "query String value")
flag.StringVar(&model, "model", "", "model String value,example: server,info")
flag.StringVar(&token, "token", "", "token Sting value")

flag.Parse()
}

if len(os.Args) == 1 {
fmt.Println(`example:
./quake -token=<token> -model=<model> -query=<query>`)
func Init() {
fmt.Println("Starting Quake Cli...")
num := len(os.Args)
if num < 2 {
fmt.Println(`
Usage of ./quake_go:
-model string
model String value (default "info")
-query string
query String value
-size string
size String value (default "10")
-start string
start String value (default "0")
-token string
token Sting value`)
start String value (default "0")`)
return
}
if token == "" {
fmt.Println("!!!!token is empty!!!!")
path := "./config.yaml"
if strings.ToLower(os.Args[1]) == "init" {
if num < 3 {
fmt.Println("!!!!token is empty !!!!")
return
}
utils.WriteYaml(path, os.Args[2])
return
}

switch strings.ToLower(model) {
token, status := utils.ReadYaml(path)
if status {
fmt.Println("!!!!please ./quake init token!!!!")
return
}
start, size := flaginit()
switch strings.ToLower(os.Args[1]) {
case "info":
apis.InfoGet(token)
case "server":
apis.SearchServicePost(query, start, size, token)
apis.InfoGet(token.Token)
case "query":
if num < 3 {
fmt.Println("!!!!query is empty !!!!")
return
}
apis.SearchServicePost(os.Args[2], start, size, token.Token)
case "host":
fmt.Println("主机数据接口待完成。。。")
case "favicon":
Expand All @@ -65,6 +68,11 @@ Usage of ./quake_go:
}
}

func Init() {
fmt.Println("Starting Quake Cli...")
func flaginit() (string, string) {
var start, size string
flag.StringVar(&size, "size", "10", "size String value")
flag.StringVar(&start, "start", "0", "start String value")

flag.Parse()
return start, size
}
55 changes: 55 additions & 0 deletions src/utils/YamlAction.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* @Author: ph4nt0mer [email protected]
* @Date: 2022-09-06 10:04:23
* @LastEditors: ph4nt0mer
* @LastEditTime: 2022-09-06 11:17:07
* @FilePath: /quake_go/src/utils/YamlAction.go
* @Description:读写yaml
*
* Copyright (c) 2022 by ph4nt0mer, All Rights Reserved.
*/
package utils

import (
"fmt"
"io/ioutil"

"gopkg.in/yaml.v2"
)

type TokenInfo struct {
Token string `yaml:"token"`
}

func WriteYaml(path string, token string) {
// 进行写yaml操作
var tokeninfo TokenInfo
tokeninfo.Token = token
data, err := yaml.Marshal(tokeninfo)
//config赋值777操作
err = ioutil.WriteFile(path, data, 0777)
if err = ioutil.WriteFile(path, data, 0777); err != nil {
fmt.Printf("token init fail!")
} else {
fmt.Printf("token init success!")
}

}

func checkError(err error) bool {
// 判断是否有错误,有错误nil,返回false,无返回true
if err != nil {
return true
}
return false
}

func ReadYaml(path string) (TokenInfo, bool) {
// 读取yaml里面的内容
content, err := ioutil.ReadFile(path)
status := checkError(err)
var token TokenInfo
err = yaml.Unmarshal(content, &token)
status = checkError(err)
return token, status
}

0 comments on commit ce4f086

Please sign in to comment.