summaryrefslogtreecommitdiff
path: root/pkg/bindings
diff options
context:
space:
mode:
authorNikolay Edigaryev <edigaryev@gmail.com>2021-02-18 01:09:21 +0300
committerNikolay Edigaryev <edigaryev@gmail.com>2021-02-18 01:14:12 +0300
commitb3f9559c87421701a026f62ca277e568158cccc0 (patch)
tree317a37859eb73096781d85b4fe292b0877e89faf /pkg/bindings
parent9699e81a0624c8505b63d9ac5b5a30980c9f5b46 (diff)
downloadpodman-b3f9559c87421701a026f62ca277e568158cccc0.tar.gz
podman-b3f9559c87421701a026f62ca277e568158cccc0.tar.bz2
podman-b3f9559c87421701a026f62ca277e568158cccc0.zip
bindings: support simple types that implement fmt.Stringer interface
Signed-off-by: Nikolay Edigaryev <edigaryev@gmail.com>
Diffstat (limited to 'pkg/bindings')
-rw-r--r--pkg/bindings/util/util.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/pkg/bindings/util/util.go b/pkg/bindings/util/util.go
index 6296fc22f..2d65ae9fd 100644
--- a/pkg/bindings/util/util.go
+++ b/pkg/bindings/util/util.go
@@ -2,6 +2,7 @@ package util
import (
"errors"
+ "fmt"
"net/url"
"reflect"
"strconv"
@@ -11,14 +12,25 @@ import (
)
func IsSimpleType(f reflect.Value) bool {
+ switch f.Interface().(type) {
+ case fmt.Stringer:
+ return true
+ }
+
switch f.Kind() {
case reflect.Bool, reflect.Int, reflect.Int64, reflect.Uint, reflect.Uint64, reflect.String:
return true
}
+
return false
}
func SimpleTypeToParam(f reflect.Value) string {
+ switch cast := f.Interface().(type) {
+ case fmt.Stringer:
+ return cast.String()
+ }
+
switch f.Kind() {
case reflect.Bool:
return strconv.FormatBool(f.Bool())
@@ -31,6 +43,7 @@ func SimpleTypeToParam(f reflect.Value) string {
case reflect.String:
return f.String()
}
+
panic("the input parameter is not a simple type")
}