[fix] Refactored GetInt, GetBool to use GetOpt.
@@ -99,8 +99,11 @@ func (opts InstallationOptions) GetString(optionName string, deploymentID string
}
func (opts InstallationOptions) GetBool(optionName string, deploymentID string) (bool, error) {
- for _, option := range opts {
- if option.Name == optionName && option.DeploymentID == deploymentID {
+ option, err := opts.GetOpt(optionName, deploymentID)
+ if err != nil {
+ return false, err
+ }
+
result, ok := option.Value.(bool)
if !ok {
panic("wrong type assertion")
@@ -108,14 +111,13 @@ func (opts InstallationOptions) GetBool(optionName string, deploymentID string)
return result, nil
}
}
- }
- return false, errors.New(optionName + " not set")
+func (opts InstallationOptions) GetInt(optionName string, deploymentID string) (int, error) {
+ option, err := opts.GetOpt(optionName, deploymentID)
+ if err != nil {
+ return 0, err
}
-func (opts InstallationOptions) GetInt(optionName string, deploymentID string) (int, error) {
- for _, option := range opts {
- if option.Name == optionName && option.DeploymentID == deploymentID {
result, ok := option.Value.(int)
if !ok {
panic("wrong type assertion")
@@ -123,10 +125,6 @@ func (opts InstallationOptions) GetInt(optionName string, deploymentID string) (
return result, nil
}
}
- }
-
- return 0, errors.New(optionName + " not set")
-}
func (opts InstallationOptions) ForDeployment(deploymentID string) InstallationOptions {
result := InstallationOptions{}
