-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
55 lines (49 loc) · 1.94 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package ltt
import (
"flag"
"io"
"os"
)
type Config struct {
// Host to bind the REST API to. default all (empty string).
APIHost string `json:"api_host"`
// Port to bind the REST API to, default 4141
APIPort int `json:"api_port"`
NumUsers int `json:"num_users"`
// How many users to spawn each second
NumSpawnPerSecond int `json:"num_spawn_per_second"`
// Default 10 seconds
RequestTimeout int `json:"request_timeout"`
// Custom user type to override the DefaultUser
UserType User `json:"-"`
// Min sleep time between tasks in seconds
MinSleepTime int `json:"min_sleep_time"`
// Max sleep time between tasks in seconds
MaxSleepTime int `json:"max_sleep_time"`
// Verbose logging
Verbose bool `json:"verbose"`
// If we should start spawning users on startup
SpawnOnStartup bool `json:"spawn_on_startup"`
// Logging params
LogOutput io.Writer `json:"-"`
LogPrefix string `json:"log_prefix"`
LogFlags int `json:"log_flags"`
}
func NewConfigFromFlags() Config {
conf := Config{}
flag.IntVar(&conf.NumUsers, "num-users", 5, "Number of users to spawn")
flag.IntVar(&conf.RequestTimeout, "request-timeout", 5, "Request timeout in seconds")
flag.IntVar(&conf.MinSleepTime, "min-sleep-time", 1, "Minimum sleep time between a user's tasks in seconds")
flag.IntVar(&conf.MaxSleepTime, "max-sleep-time", 10, "Maximum sleep time between a user's tasks in seconds")
flag.IntVar(&conf.NumSpawnPerSecond, "num-spawn-per-sec", 1, "Number of user to spawn per second")
flag.StringVar(&conf.APIHost, "api-host", "", "REST API port to bind to.")
flag.StringVar(&conf.LogPrefix, "log-prefix", "", "Logging prefix")
flag.IntVar(&conf.APIPort, "api-port", 4141, "REST API port to bind to.")
flag.BoolVar(&conf.Verbose, "verbose", false, "Verbose logging")
flag.BoolVar(&conf.SpawnOnStartup, "spawn-on-startup", false, "If true, spawning will begin on startup")
flag.Parse()
if conf.LogOutput == nil {
conf.LogOutput = os.Stdout
}
return conf
}