Improve ListBindGenericSlice

- Add support for encoding.TextMarshaler and encoding.TextUnmarshaler
master
David Vogel 1 year ago
parent a0e2314138
commit a60a1f4af7

@ -1,6 +1,7 @@
package input
import (
"encoding"
"fmt"
"strconv"
@ -35,6 +36,12 @@ func (l ListBindGenericSlice[T]) ListKeyValuePairs() []ListKeyValuePair {
var str string
switch v := any(entry).(type) {
case encoding.TextMarshaler:
if text, err := v.MarshalText(); err != nil {
str = fmt.Sprintf("%d: %s", i, err.Error())
} else {
str = string(text)
}
case string:
str = v
case int:
@ -89,6 +96,10 @@ func (l ListBindGenericSlice[T]) ListDeleteKey(key string) bool {
func (l ListBindGenericSlice[T]) ListAddKeyValuePair(key, value string) error {
var val T
switch v := any(&val).(type) {
case encoding.TextUnmarshaler:
if err := v.UnmarshalText([]byte(value)); err != nil {
return err
}
case *string:
*v = value
case *int:

Loading…
Cancel
Save