-
Notifications
You must be signed in to change notification settings - Fork 7
/
path.go
41 lines (31 loc) · 857 Bytes
/
path.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 config
import (
"fmt"
"github.com/bazelbuild/rules_go/go/tools/bazel"
)
const (
_template = "config/config.%s.yml"
)
type ConfigFilePathResolver interface {
Resolve() (string, error)
}
type Resolver struct {
Environment Environment
Template string
}
func ProvideConfigPathResolver(e Environment) ConfigFilePathResolver {
return &Resolver{Environment: e, Template: _template}
}
var _ ConfigFilePathResolver = (*Resolver)(nil)
func (r Resolver) Resolve() (string, error) {
configurationFileName := configurationFileName(r.Environment)
location := fmt.Sprintf(r.Template, configurationFileName)
path, err := bazel.Runfile(location)
if err != nil {
return "", fmt.Errorf(location)
}
return path, nil
}
func configurationFileName(e Environment) string {
return fmt.Sprintf("%s.%s.%s", e.Configuration, e.Stage, e.Provider)
}