Skip to content

Commit 352761a

Browse files
committed
update command
1 parent ba0fd70 commit 352761a

File tree

7 files changed

+55
-51
lines changed

7 files changed

+55
-51
lines changed

cmd/command.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package cmd
22

33
import (
4+
"os"
45
"fmt"
56
"github.com/spf13/cobra"
7+
8+
log "github.com/sirupsen/logrus"
69
)
710

811

@@ -14,7 +17,8 @@ var (
1417
)
1518

1619
var rootCmd = &cobra.Command{
17-
Use: "",
20+
Use: "bomb",
21+
Args: cobra.NoArgs,
1822
}
1923

2024
var versionCmd = &cobra.Command{
@@ -25,7 +29,14 @@ var versionCmd = &cobra.Command{
2529

2630

2731
func Execute(){
28-
rootCmd.Execute()
32+
if err := rootCmd.Execute(); err != nil {
33+
log.Fatal(err)
34+
}
35+
// the function MarkFlagRequired looks like dosen't work,
36+
// so judg it by hand
37+
if Phone == "" {
38+
log.Fatal("phone is empty")
39+
}
2940
}
3041

3142
func init(){
@@ -34,9 +45,12 @@ func init(){
3445
rootCmd.Flags().StringVarP(&Phone, "phone", "p", "", "phone number")
3546
rootCmd.Flags().StringVarP(&AreaCode, "areacode", "a", "", "the phone number area code, example: +86")
3647
rootCmd.AddCommand(versionCmd)
48+
49+
rootCmd.MarkFlagRequired("phone")
3750
}
3851

3952

4053
func showVersion(cmd *cobra.Command, args []string) {
4154
fmt.Println("version 1.0.0")
55+
os.Exit(0)
4256
}

core/core.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func bomb(api *models.API) {
2929
for {
3030
time.Sleep(time.Duration(gap)* time.Second)
3131
fmt.Printf("bomb %s with %s\n", cmd.Phone, api.Name)
32-
//sender.Run(api)
32+
sender.Run(*api)
3333
}
3434
}
3535

core/sender.go

+32-44
Original file line numberDiff line numberDiff line change
@@ -11,54 +11,17 @@ import (
1111
"bomb/models"
1212
)
1313

14-
type Send struct {}
1514

1615
type HttpSender struct {
17-
Send
1816
}
1917

2018
type HttpsSender struct {
21-
Send
2219
}
2320

2421
type TcpSender struct {
25-
Send
26-
}
27-
28-
func (s Send) Init () {
29-
// TODO
30-
}
31-
32-
//func (s *Send) SendData (api models.API) {
33-
// fmt.Println(api.Url)
34-
// // TODO
35-
//}
36-
37-
func (s Send) Recv () {
38-
//TODO
39-
}
40-
41-
func (s *Send) Run (api models.API) {
42-
// s.SendData(api)
43-
}
44-
45-
46-
func NewSender(way string) models.Sender {
47-
switch way {
48-
case "http":
49-
return &HttpSender{}
50-
case "https": {
51-
return &HttpsSender{}
52-
};
53-
case "tcp": {
54-
return &TcpSender{}
55-
};
56-
default: {
57-
return &HttpSender{}
58-
}
59-
}
6022
}
6123

24+
func (h HttpSender) Init() {}
6225

6326
func (h *HttpSender) SendData (api models.API) {
6427
switch api.Method {
@@ -124,10 +87,18 @@ func (h *HttpSender) SendData (api models.API) {
12487
}
12588
}
12689

90+
func (h *HttpSender) Run (api models.API) {
91+
h.SendData(api)
92+
}
93+
94+
func (h *HttpsSender) Init () {}
95+
12796
func (h *HttpsSender) SendData (api models.API) {
12897
switch api.Method {
12998
case 0: {
130-
tr := &http.Transport{}
99+
tr := &http.Transport{
100+
TLSClientConfig:&tls.Config{InsecureSkipVerify: true},
101+
}
131102
client := &http.Client{Transport: tr}
132103
req, err := http.NewRequest("GET", api.Url, nil)
133104
if err != nil {
@@ -175,17 +146,34 @@ func (h *HttpsSender) SendData (api models.API) {
175146
}
176147
}
177148

178-
func (h *HttpsSender) Init () {}
179-
func (h *HttpsSender) Recv () {}
180149
func (h *HttpsSender) Run (api models.API) {
181150
h.SendData(api)
182151
}
183-
func (h *HttpSender) Run (api models.API) {
184-
h.SendData(api)
185-
}
152+
153+
func (t *TcpSender) Init () {}
186154

187155
func (t *TcpSender) SendData (api models.API) {
188156
fmt.Println(api.Url)
189157
// TODO
190158
}
191159

160+
func (t *TcpSender) Run (api models.API) {
161+
t.SendData(api)
162+
}
163+
164+
func NewSender(way string) models.Sender {
165+
switch way {
166+
case "http":
167+
return &HttpSender{}
168+
case "https": {
169+
return &HttpsSender{}
170+
};
171+
case "tcp": {
172+
return &TcpSender{}
173+
};
174+
default: {
175+
return &HttpSender{}
176+
}
177+
}
178+
}
179+

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/coreos/go-etcd v2.0.0+incompatible // indirect
99
github.com/cpuguy83/go-md2man v1.0.10 // indirect
1010
github.com/mitchellh/go-homedir v1.1.0 // indirect
11+
github.com/sirupsen/logrus v1.8.1 // indirect
1112
github.com/spf13/cobra v1.2.1 // indirect
1213
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8 // indirect
1314
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77 // indirect

go.sum

+3
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
209209
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
210210
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
211211
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
212+
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
213+
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
212214
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
213215
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
214216
github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY=
@@ -366,6 +368,7 @@ golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7w
366368
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
367369
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
368370
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
371+
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
369372
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
370373
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
371374
golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

models/models.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type API struct {
3434
type Sender interface {
3535
Init()
3636
SendData(API)
37-
Recv()
37+
//Recv()
3838
Run(API)
3939
}
4040

utils/utils.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ func LoadDatas(){
3131
newDatas = append(newDatas, api)
3232
}
3333
}
34-
conf.Datas = newDatas
3534

36-
fmt.Println(conf.Datas[0].GetMethod())
37-
fmt.Println(conf.Datas[0].GetDataType())
35+
conf.Datas = newDatas
3836
}
3937

4038

0 commit comments

Comments
 (0)