UserConfig validation

This commit is contained in:
oakio 2024-02-25 17:38:58 +03:00 committed by Stefan Haller
parent 2b5c814080
commit 5c3aacb4cb
3 changed files with 75 additions and 0 deletions

View file

@ -0,0 +1,22 @@
package config
import (
"fmt"
"slices"
"strings"
)
func (config *UserConfig) Validate() error {
if err := validateEnum("gui.statusPanelView", config.Gui.StatusPanelView, []string{"dashboard", "allBranchesLog"}); err != nil {
return err
}
return nil
}
func validateEnum(name string, value string, allowedValues []string) error {
if slices.Contains(allowedValues, value) {
return nil
}
allowedValuesStr := strings.Join(allowedValues, ", ")
return fmt.Errorf("Unexpected value '%s' for '%s'. Allowed values: %s", value, name, allowedValuesStr)
}