-
Notifications
You must be signed in to change notification settings - Fork 9
/
config.go
41 lines (34 loc) · 888 Bytes
/
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
package experiment
import "time"
// Config represents the configuration options for an experiment.
type Config struct {
Percentage int
Concurrency bool
Timeout *time.Duration
}
// ConfigFunc represents a function that knows how to set a configuration option.
type ConfigFunc func(*Config)
// WithPercentage returns a new func(*Config) that sets the percentage.
func WithPercentage(p int) ConfigFunc {
return func(c *Config) {
c.Percentage = p
}
}
func WithTimeout(t time.Duration) ConfigFunc {
return func(c *Config) {
c.Timeout = &t
}
}
// WithConcurrency forces the experiment to run concurrently
func WithConcurrency() ConfigFunc {
return func(c *Config) {
c.Concurrency = true
}
}
// WithDefaultConfig returns a new configuration with defaults.
func WithDefaultConfig() ConfigFunc {
return func(c *Config) {
c.Percentage = 0
c.Concurrency = false
}
}