-
Notifications
You must be signed in to change notification settings - Fork 12
/
custom_api_decorator.go
64 lines (55 loc) · 1.62 KB
/
custom_api_decorator.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
package config
import (
"fmt"
"regexp"
"strings"
"github.com/antham/envh"
)
func getCustomAPIDecoratorMandatoryParamsRefs() []ref {
return []ref{
{
&chyleConfig.DECORATORS.CUSTOMAPI.ENDPOINT.URL,
[]string{"CHYLE", "DECORATORS", "CUSTOMAPI", "ENDPOINT", "URL"},
},
{
&chyleConfig.DECORATORS.CUSTOMAPI.CREDENTIALS.TOKEN,
[]string{"CHYLE", "DECORATORS", "CUSTOMAPI", "CREDENTIALS", "TOKEN"},
},
}
}
func getCustomAPIDecoratorFeatureRefs() []*bool {
return []*bool{
&chyleConfig.FEATURES.DECORATORS.ENABLED,
&chyleConfig.FEATURES.DECORATORS.CUSTOMAPI,
}
}
func getCustomAPIDecoratorCustomValidationFuncs(config *envh.EnvTree) []func() error {
return []func() error{
func() error {
keyChain := []string{"CHYLE", "DECORATORS", "CUSTOMAPI", "ENDPOINT", "URL"}
URL := config.FindStringUnsecured(keyChain...)
if !regexp.MustCompile(`{{\s*ID\s*}}`).MatchString(URL) {
return EnvValidationError{fmt.Sprintf(`ensure you defined a placeholder {{ID}} in URL defined in "%s"`, strings.Join(keyChain, "_")), strings.Join(keyChain, "_")}
}
return nil
},
}
}
func getCustomAPIDecoratorCustomSettersFuncs() []func(*CHYLE) {
return []func(*CHYLE){}
}
func newCustomAPIDecoratorConfigurator(config *envh.EnvTree) configurater {
return &apiDecoratorConfigurator{
config: config,
apiDecoratorConfig: apiDecoratorConfig{
"CUSTOMAPIID",
"customApiId",
"CUSTOMAPI",
&chyleConfig.DECORATORS.CUSTOMAPI.KEYS,
getCustomAPIDecoratorMandatoryParamsRefs(),
getCustomAPIDecoratorFeatureRefs(),
getCustomAPIDecoratorCustomValidationFuncs(config),
getCustomAPIDecoratorCustomSettersFuncs(),
},
}
}