-
Notifications
You must be signed in to change notification settings - Fork 26
/
helper.go
49 lines (38 loc) · 960 Bytes
/
helper.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
package config
import (
"path/filepath"
builder "github.com/aserto-dev/service-host"
"github.com/aserto-dev/topaz/pkg/cli/cc"
"github.com/samber/lo"
)
type currentConfig struct {
*Loader
err error
}
func CurrentConfig() *currentConfig {
cfg, err := LoadConfiguration(filepath.Join(cc.GetTopazCfgDir(), "config.yaml"))
if err != nil {
return ¤tConfig{Loader: nil, err: err}
}
return ¤tConfig{Loader: cfg, err: nil}
}
func (c *currentConfig) Ports() ([]string, error) {
if c.err != nil {
return []string{}, c.err
}
return c.GetPorts()
}
func (c *currentConfig) Services() ([]string, error) {
if c.err != nil {
return []string{}, c.err
}
return lo.MapToSlice(c.Configuration.APIConfig.Services, func(k string, v *builder.API) string {
return k
}), nil
}
func (c *currentConfig) HealthService() (string, error) {
if c.err != nil {
return "", c.err
}
return c.Configuration.APIConfig.Health.ListenAddress, nil
}