mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 05:15:47 +00:00
make more error const for params config
This commit is contained in:
@@ -16,6 +16,8 @@ var (
|
|||||||
ErrParamNotFound = errors.New("not found")
|
ErrParamNotFound = errors.New("not found")
|
||||||
ErrParamNotString = errors.New("not a string")
|
ErrParamNotString = errors.New("not a string")
|
||||||
ErrParamNotNumber = errors.New("not a number")
|
ErrParamNotNumber = errors.New("not a number")
|
||||||
|
ErrParamNotBool = errors.New("not a boolean")
|
||||||
|
ErrParamNotSlice = errors.New("not a slice")
|
||||||
)
|
)
|
||||||
|
|
||||||
func (p Params) GetString(key string) (string, error) {
|
func (p Params) GetString(key string) (string, error) {
|
||||||
@@ -56,7 +58,7 @@ func (p Params) GetBool(key string) (bool, error) {
|
|||||||
|
|
||||||
boolValue, ok := value.(bool)
|
boolValue, ok := value.(bool)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false, errors.New("not a boolean")
|
return false, ErrParamNotBool
|
||||||
}
|
}
|
||||||
return boolValue, nil
|
return boolValue, nil
|
||||||
}
|
}
|
||||||
@@ -69,7 +71,7 @@ func (p Params) GetStringSlice(key string) ([]string, error) {
|
|||||||
|
|
||||||
interfaceSlice, ok := value.([]any)
|
interfaceSlice, ok := value.([]any)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("not a slice")
|
return nil, ErrParamNotSlice
|
||||||
}
|
}
|
||||||
|
|
||||||
stringSlice := make([]string, len(interfaceSlice))
|
stringSlice := make([]string, len(interfaceSlice))
|
||||||
|
|||||||
Reference in New Issue
Block a user