add function to get string slice from params

This commit is contained in:
Joel Wetzell
2026-03-02 09:07:31 -06:00
parent 9d14e5929f
commit cd264d9ed4

View File

@@ -2,6 +2,7 @@ package config
import (
"errors"
"fmt"
)
type Config struct {
@@ -60,6 +61,28 @@ func (p Params) GetBool(key string) (bool, error) {
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 {
Id string `json:"id"`
Type string `json:"type"`