mirror of
https://github.com/containers/podman.git
synced 2025-06-24 03:08:13 +08:00
bindings: support simple types that implement fmt.Stringer interface
Signed-off-by: Nikolay Edigaryev <edigaryev@gmail.com>
This commit is contained in:
@ -2,6 +2,7 @@ package util
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -11,14 +12,25 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func IsSimpleType(f reflect.Value) bool {
|
func IsSimpleType(f reflect.Value) bool {
|
||||||
|
switch f.Interface().(type) {
|
||||||
|
case fmt.Stringer:
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
switch f.Kind() {
|
switch f.Kind() {
|
||||||
case reflect.Bool, reflect.Int, reflect.Int64, reflect.Uint, reflect.Uint64, reflect.String:
|
case reflect.Bool, reflect.Int, reflect.Int64, reflect.Uint, reflect.Uint64, reflect.String:
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func SimpleTypeToParam(f reflect.Value) string {
|
func SimpleTypeToParam(f reflect.Value) string {
|
||||||
|
switch cast := f.Interface().(type) {
|
||||||
|
case fmt.Stringer:
|
||||||
|
return cast.String()
|
||||||
|
}
|
||||||
|
|
||||||
switch f.Kind() {
|
switch f.Kind() {
|
||||||
case reflect.Bool:
|
case reflect.Bool:
|
||||||
return strconv.FormatBool(f.Bool())
|
return strconv.FormatBool(f.Bool())
|
||||||
@ -31,6 +43,7 @@ func SimpleTypeToParam(f reflect.Value) string {
|
|||||||
case reflect.String:
|
case reflect.String:
|
||||||
return f.String()
|
return f.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
panic("the input parameter is not a simple type")
|
panic("the input parameter is not a simple type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user