Improve ListBindGenericSlice
- Add support for encoding.TextMarshaler and encoding.TextUnmarshaler
This commit is contained in:
parent
a0e2314138
commit
a60a1f4af7
@ -1,6 +1,7 @@
|
|||||||
package input
|
package input
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@ -35,6 +36,12 @@ func (l ListBindGenericSlice[T]) ListKeyValuePairs() []ListKeyValuePair {
|
|||||||
|
|
||||||
var str string
|
var str string
|
||||||
switch v := any(entry).(type) {
|
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:
|
case string:
|
||||||
str = v
|
str = v
|
||||||
case int:
|
case int:
|
||||||
@ -89,6 +96,10 @@ func (l ListBindGenericSlice[T]) ListDeleteKey(key string) bool {
|
|||||||
func (l ListBindGenericSlice[T]) ListAddKeyValuePair(key, value string) error {
|
func (l ListBindGenericSlice[T]) ListAddKeyValuePair(key, value string) error {
|
||||||
var val T
|
var val T
|
||||||
switch v := any(&val).(type) {
|
switch v := any(&val).(type) {
|
||||||
|
case encoding.TextUnmarshaler:
|
||||||
|
if err := v.UnmarshalText([]byte(value)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
case *string:
|
case *string:
|
||||||
*v = value
|
*v = value
|
||||||
case *int:
|
case *int:
|
||||||
|
Loading…
Reference in New Issue
Block a user