-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
61 lines (54 loc) · 1.15 KB
/
config.go
File metadata and controls
61 lines (54 loc) · 1.15 KB
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
package gophernaut
import (
"fmt"
"io/ioutil"
"gopkg.in/yaml.v2"
)
/*
Config is a Gophernaught config structure used to parse gophernaut.conf
*/
type Config struct {
Host string
Port int
Pool struct {
Size int
Template struct {
Name string
Hostname string
Executable string
}
}
}
func check(e error) {
if e != nil {
panic(e)
}
}
/*
ReadConfig reads gophernaut.conf and returns a Config object
*/
func ReadConfig() *Config {
data, error := ioutil.ReadFile("etc/template.conf")
check(error)
c := Config{}
yaml.Unmarshal(data, &c)
return &c
}
// GetExecutables uses our config to provide a set of processes to start
func (c *Config) GetExecutables() []string {
var executables []string
for x := 0; x < c.Pool.Size; x++ {
executables = append(executables,
fmt.Sprintf(c.Pool.Template.Executable, 8080+x))
}
return executables
}
// GetHostnames uses our config to provide a set of hostnames to dispatch requests to
func (c *Config) GetHostnames() []string {
var hostnames []string
for x := 0; x < c.Pool.Size; x++ {
hostnames = append(hostnames,
fmt.Sprintf(c.Pool.Template.Hostname, 8080+x))
}
return hostnames
}