From cd264d9ed4ba0fd7d87f551ec9027ff0d0502e26 Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Mon, 2 Mar 2026 09:07:31 -0600 Subject: [PATCH] add function to get string slice from params --- internal/config/config.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/internal/config/config.go b/internal/config/config.go index 16b24f9..5cdfe9c 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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"`