Files
cloud-services/pkg/redisv2/tool.go

32 lines
732 B
Go

package redisv2
import (
"errors"
"fmt"
)
var ErrUnEvenResults = errors.New("uneven number of results in interface array")
// Except an even number of results in the array
func InterfaceArrayToStringMap(array []interface{})(result map[string]string, err error){
if len(array) %2 != 0 {
err = ErrUnEvenResults
return
}
result = make(map[string]string)
for x := 0; x < len(array); x += 2 {
key, ok := array[x].(string)
if !ok {
err =errors.Join(err, fmt.Errorf("failed to convert key %v to string", array[x]))
continue
}
value, ok := array[x+1].(string)
if !ok {
err =errors.Join(err, fmt.Errorf("failed to convert value %v to string", array[x+1]))
continue
}
result[key] = value
}
return
}