code cleanup
This commit is contained in:
22
main.go
22
main.go
@@ -39,7 +39,7 @@ var (
|
||||
journalLog = flag.Bool("journal", false, "Log to systemd journal instead of stdout")
|
||||
configFlag = flag.String("config", "config.yaml", "Set config file to use")
|
||||
reBandwidth = regexp.MustCompile(`(?m)bandwidth\s(\d+)Mbit`)
|
||||
NoResponseError = errors.New("no response")
|
||||
ErrorNoResponse = errors.New("no response")
|
||||
)
|
||||
|
||||
type UploadManager struct {
|
||||
@@ -47,7 +47,7 @@ type UploadManager struct {
|
||||
}
|
||||
|
||||
func (m UploadManager) Upload() (float64, error) {
|
||||
tcCmd := exec.Command("tc", "qdisc", "show", "dev", conf.UploadInterface)
|
||||
tcCmd := exec.Command("tc", "qdisc", "show", "dev", conf.UploadInterface) //nolint:gosec
|
||||
out, err := tcCmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -64,7 +64,8 @@ func (m UploadManager) Upload() (float64, error) {
|
||||
}
|
||||
|
||||
func (m UploadManager) SetUpload(upload float64) (float64, error) {
|
||||
tcCmd := exec.Command("tc", "qdisc", "change", "dev", conf.UploadInterface, "root", "cake", "bandwidth", fmt.Sprintf("%dMbit", int(upload)))
|
||||
tcCmd := exec.Command("tc", "qdisc", "change", "dev", conf.UploadInterface, "root", "cake", "bandwidth", //nolint:gosec
|
||||
fmt.Sprintf("%dMbit", int(upload)))
|
||||
log.Debugf("[TC] exec %s", tcCmd.String())
|
||||
out, err := tcCmd.CombinedOutput()
|
||||
if err != nil {
|
||||
@@ -115,9 +116,10 @@ func doPing(host string, count int, interval time.Duration) (*ping.Statistics, e
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Debugf("[PING] %s: %s±%s %d%% loss", host, pinger.Statistics().AvgRtt, pinger.Statistics().StdDevRtt, pinger.Statistics().PacketLoss)
|
||||
log.Debugf("[PING] %s: %s±%s %d%% loss", host, pinger.Statistics().AvgRtt, pinger.Statistics().StdDevRtt,
|
||||
int(pinger.Statistics().PacketLoss))
|
||||
if pinger.Statistics().PacketLoss == 100 {
|
||||
return nil, NoResponseError
|
||||
return nil, ErrorNoResponse
|
||||
}
|
||||
return pinger.Statistics(), nil
|
||||
}
|
||||
@@ -192,7 +194,7 @@ outerLoop:
|
||||
stats, err = doPing(conf.Host, conf.ConformationPPP, time.Second)
|
||||
if err != nil {
|
||||
log.Warningf("ping to %s failed: %v", conf.Host, err)
|
||||
if !errors.Is(err, NoResponseError) {
|
||||
if !errors.Is(err, ErrorNoResponse) {
|
||||
time.Sleep(time.Duration(conf.Interval) * time.Minute)
|
||||
}
|
||||
continue
|
||||
@@ -244,11 +246,7 @@ func main() {
|
||||
}
|
||||
}()
|
||||
|
||||
killLoop:
|
||||
for {
|
||||
select {
|
||||
case <-killSignals:
|
||||
break killLoop
|
||||
}
|
||||
for range killSignals {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user