mirror of
https://github.com/buger/goreplay.git
synced 2024-04-21 12:32:02 +00:00
Change flag name, use of DurationVar instead of int
This commit is contained in:
@@ -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
@@ -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.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user