forked from influxdata/influxdb
/
config.go
96 lines (78 loc) · 2.32 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package stress
import (
"github.com/BurntSushi/toml"
)
// Config is a struct for the Stress test configuration
type Config struct {
Provision Provision `toml:"provision"`
Write Write `toml:"write"`
Read Read `toml:"read"`
}
// Provision is a struct that contains the configuration
// parameters for all implemented Provisioner's.
type Provision struct {
Basic BasicProvisioner `toml:"basic"`
}
// Write is a struct that contains the configuration
// parameters for the stress test Writer.
type Write struct {
PointGenerators PointGenerators `toml:"point_generator"`
InfluxClients InfluxClients `toml:"influx_client"`
}
// PointGenerators is a struct that contains the configuration
// parameters for all implemented PointGenerator's.
type PointGenerators struct {
Basic BasicPointGenerator `toml:"basic"`
}
// InfluxClients is a struct that contains the configuration
// parameters for all implemented InfluxClient's.
type InfluxClients struct {
Basic BasicClient `toml:"basic"`
}
// Read is a struct that contains the configuration
// parameters for the stress test Reader.
type Read struct {
QueryGenerators QueryGenerators `toml:"query_generator"`
QueryClients QueryClients `toml:"query_client"`
}
// QueryGenerators is a struct that contains the configuration
// parameters for all implemented QueryGenerator's.
type QueryGenerators struct {
Basic BasicQuery `toml:"basic"`
}
// QueryClients is a struct that contains the configuration
// parameters for all implemented QueryClient's.
type QueryClients struct {
Basic BasicQueryClient `toml:"basic"`
}
// NewConfig returns a pointer to a Config
func NewConfig(s string) (*Config, error) {
var c *Config
var err error
if s == "" {
c, err = BasicStress()
} else {
c, err = DecodeFile(s)
}
return c, err
}
// DecodeFile takes a file path for a toml config file
// and returns a pointer to a Config Struct.
func DecodeFile(s string) (*Config, error) {
t := &Config{}
// Decode the toml file
if _, err := toml.DecodeFile(s, t); err != nil {
return nil, err
}
return t, nil
}
// DecodeConfig takes a file path for a toml config file
// and returns a pointer to a Config Struct.
func DecodeConfig(s string) (*Config, error) {
t := &Config{}
// Decode the toml file
if _, err := toml.Decode(s, t); err != nil {
return nil, err
}
return t, nil
}