mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-26 21:05:30 +00:00
add function to get string slice from params
This commit is contained in:
@@ -2,6 +2,7 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
@@ -60,6 +61,28 @@ func (p Params) GetBool(key string) (bool, error) {
|
|||||||
return boolValue, nil
|
return boolValue, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p Params) GetStringSlice(key string) ([]string, error) {
|
||||||
|
value, ok := p[key]
|
||||||
|
if !ok {
|
||||||
|
return nil, ErrParamNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
interfaceSlice, ok := value.([]any)
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("not a slice")
|
||||||
|
}
|
||||||
|
|
||||||
|
stringSlice := make([]string, len(interfaceSlice))
|
||||||
|
for i, v := range interfaceSlice {
|
||||||
|
str, ok := v.(string)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("element at index %d is not a string", i)
|
||||||
|
}
|
||||||
|
stringSlice[i] = str
|
||||||
|
}
|
||||||
|
return stringSlice, nil
|
||||||
|
}
|
||||||
|
|
||||||
type ModuleConfig struct {
|
type ModuleConfig struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
|
|||||||
Reference in New Issue
Block a user