Change flag name, use of DurationVar instead of int

This commit is contained in:
Or Tzabary
2016-07-08 19:04:24 +03:00
parent c78933f1df
commit 6620d25626
2 changed files with 11 additions and 10 deletions
+6 -7
View File
@@ -22,7 +22,6 @@ var (
mode string
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
memprofile = flag.String("memprofile", "", "write memory profile to this file")
timeout = flag.Int("timeout", 0, "timeout to stop gor, value in seconds")
)
func loggingMiddleware(next http.Handler) http.Handler {
@@ -89,10 +88,10 @@ func main() {
os.Exit(1)
}()
if *timeout >= 1 {
log.Println("Running gor with timeout of", *timeout, "seconds")
if Settings.exitAfter >= 1 {
log.Println("Running gor for a duration of", Settings.exitAfter)
stop := make(chan int)
timeoutGor(stop, *timeout)
stopAfter(stop, Settings.exitAfter)
Start(stop)
} else {
@@ -129,9 +128,9 @@ func profileMEM(memprofile string) {
}
}
func timeoutGor(stop chan int, seconds int) {
time.AfterFunc(time.Duration(seconds)*time.Second, func() {
log.Println("Stopping gor after", seconds, "seconds")
func stopAfter(stop chan int, exitAfter time.Duration) {
time.AfterFunc(exitAfter, func() {
log.Println("Stopping gor, duration of", exitAfter, "reached")
close(stop)
})
}
+5 -3
View File
@@ -25,9 +25,10 @@ func (h *MultiOption) Set(value string) error {
// AppSettings is the struct of main configuration
type AppSettings struct {
verbose bool
debug bool
stats bool
verbose bool
debug bool
stats bool
exitAfter time.Duration
splitOutput bool
@@ -74,6 +75,7 @@ func init() {
flag.BoolVar(&Settings.verbose, "verbose", false, "Turn on more verbose output")
flag.BoolVar(&Settings.debug, "debug", false, "Turn on debug output, shows all intercepted traffic. Works only when with `verbose` flag")
flag.BoolVar(&Settings.stats, "stats", false, "Turn on queue stats output")
flag.DurationVar(&Settings.exitAfter, "exit-after", 0, "exit after specified duration")
flag.BoolVar(&Settings.splitOutput, "split-output", false, "By default each output gets same traffic. If set to `true` it splits traffic equally among all outputs.")