Changed from Retry to Count
This commit is contained in:
parent
56b9d39ba9
commit
ac5e1d0bd3
|
@ -7,7 +7,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Option interface {
|
type Option interface {
|
||||||
GetRetry() int
|
GetCount() int
|
||||||
GetInterval() int
|
GetInterval() int
|
||||||
GetDeadline() int
|
GetDeadline() int
|
||||||
Validate()
|
Validate()
|
||||||
|
@ -35,13 +35,13 @@ type Result interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type PingOption struct {
|
type PingOption struct {
|
||||||
Retry int `json:"retry,omitempty"`
|
Count int `json:"count,omitempty"`
|
||||||
Interval int `json:"interval,omitempty"`
|
Interval int `json:"interval,omitempty"`
|
||||||
Deadline int `json:"deadline,omitempty"`
|
Deadline int `json:"deadline,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *PingOption) GetRetry() int {
|
func (o *PingOption) GetCount() int {
|
||||||
return o.Retry
|
return o.Count
|
||||||
}
|
}
|
||||||
func (o *PingOption) GetInterval() int {
|
func (o *PingOption) GetInterval() int {
|
||||||
return o.Interval
|
return o.Interval
|
||||||
|
@ -50,8 +50,8 @@ func (o *PingOption) GetDeadline() int {
|
||||||
return o.Deadline
|
return o.Deadline
|
||||||
}
|
}
|
||||||
func (o *PingOption) Validate() {
|
func (o *PingOption) Validate() {
|
||||||
if 0 >= o.Retry {
|
if 0 >= o.Count {
|
||||||
o.Retry = 1
|
o.Count = 1
|
||||||
}
|
}
|
||||||
if 0 >= o.Interval {
|
if 0 >= o.Interval {
|
||||||
o.Interval = 1
|
o.Interval = 1
|
||||||
|
|
|
@ -10,7 +10,7 @@ func Ping(destination string, option Option) (Result, error) {
|
||||||
|
|
||||||
params := make([]string, 0)
|
params := make([]string, 0)
|
||||||
params = append(params, destination)
|
params = append(params, destination)
|
||||||
params = append(params, fmt.Sprintf("-c %d", option.GetRetry()))
|
params = append(params, fmt.Sprintf("-c %d", option.GetCount()))
|
||||||
params = append(params, fmt.Sprintf("-i %d", option.GetInterval()))
|
params = append(params, fmt.Sprintf("-i %d", option.GetInterval()))
|
||||||
|
|
||||||
pCmd := exec.Command("ping", params...)
|
pCmd := exec.Command("ping", params...)
|
||||||
|
|
|
@ -21,7 +21,7 @@ func TestPing(t *testing.T) {
|
||||||
args: args{
|
args: args{
|
||||||
destination: "192.168.1.1",
|
destination: "192.168.1.1",
|
||||||
option: &PingOption{
|
option: &PingOption{
|
||||||
Retry: 4,
|
Count: 4,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -11,7 +11,7 @@ func Ping(destination string, option Option) (Result, error) {
|
||||||
|
|
||||||
params := make([]string, 0)
|
params := make([]string, 0)
|
||||||
params = append(params, destination)
|
params = append(params, destination)
|
||||||
params = append(params, fmt.Sprintf("-c %d", option.GetRetry()))
|
params = append(params, fmt.Sprintf("-c %d", option.GetCount()))
|
||||||
params = append(params, fmt.Sprintf("-i %d", option.GetInterval()))
|
params = append(params, fmt.Sprintf("-i %d", option.GetInterval()))
|
||||||
|
|
||||||
pCmd := exec.Command("ping", params...)
|
pCmd := exec.Command("ping", params...)
|
||||||
|
|
|
@ -18,7 +18,7 @@ func TestPing(t *testing.T) {
|
||||||
args: args{
|
args: args{
|
||||||
destination: "192.168.1.1",
|
destination: "192.168.1.1",
|
||||||
option: &PingOption{
|
option: &PingOption{
|
||||||
Retry: 4,
|
Count: 4,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
func TestPingOptions_Validate(t *testing.T) {
|
func TestPingOptions_Validate(t *testing.T) {
|
||||||
type fields struct {
|
type fields struct {
|
||||||
Retry int
|
Count int
|
||||||
Interval int
|
Interval int
|
||||||
Deadline int
|
Deadline int
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ func TestPingOptions_Validate(t *testing.T) {
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
o := &PingOption{
|
o := &PingOption{
|
||||||
Retry: tt.fields.Retry,
|
Count: tt.fields.Count,
|
||||||
Interval: tt.fields.Interval,
|
Interval: tt.fields.Interval,
|
||||||
Deadline: tt.fields.Deadline,
|
Deadline: tt.fields.Deadline,
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ func Ping(destination string, option Option) (Result, error) {
|
||||||
|
|
||||||
params := make([]string, 0)
|
params := make([]string, 0)
|
||||||
params = append(params, "/C")
|
params = append(params, "/C")
|
||||||
params = append(params, fmt.Sprintf("chcp 437 && ping %s -n %d -w %d", destination, option.GetRetry(), option.GetDeadline()*1000))
|
params = append(params, fmt.Sprintf("chcp 437 && ping %s -n %d -w %d", destination, option.GetCount(), option.GetDeadline()*1000))
|
||||||
|
|
||||||
pCmd := exec.Command("cmd.exe", params...)
|
pCmd := exec.Command("cmd.exe", params...)
|
||||||
output, err := pCmd.CombinedOutput()
|
output, err := pCmd.CombinedOutput()
|
||||||
|
|
|
@ -18,7 +18,7 @@ func TestPing(t *testing.T) {
|
||||||
args: args{
|
args: args{
|
||||||
destination: "192.168.1.1",
|
destination: "192.168.1.1",
|
||||||
option: &PingOption{
|
option: &PingOption{
|
||||||
Retry: 4,
|
Count: 4,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user