-
Notifications
You must be signed in to change notification settings - Fork 572
/
params.go
39 lines (32 loc) · 915 Bytes
/
params.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
package types
import (
"fmt"
"strings"
)
const (
// DefaultHostEnabled is the default value for the host param (set to true)
DefaultHostEnabled = true
)
// NewParams creates a new parameter configuration for the host submodule
func NewParams(enableHost bool, allowMsgs []string) Params {
return Params{
HostEnabled: enableHost,
AllowMessages: allowMsgs,
}
}
// DefaultParams is the default parameter configuration for the host submodule
func DefaultParams() Params {
return NewParams(DefaultHostEnabled, []string{AllowAllHostMsgs})
}
// Validate validates all host submodule parameters
func (p Params) Validate() error {
return validateAllowlist(p.AllowMessages)
}
func validateAllowlist(allowMsgs []string) error {
for _, typeURL := range allowMsgs {
if strings.TrimSpace(typeURL) == "" {
return fmt.Errorf("parameter must not contain empty strings: %s", allowMsgs)
}
}
return nil
}