summaryrefslogtreecommitdiff
path: root/pkg/bindings/play
diff options
context:
space:
mode:
authorMatej Vasek <mvasek@redhat.com>2021-02-02 19:36:55 +0100
committerMatej Vasek <mvasek@redhat.com>2021-02-02 19:49:41 +0100
commitac3bd4c3318d2e15680d7dd62e76f5f58db4d425 (patch)
tree6b00be188d8083374a3f13ae7b2a7c6d4f265611 /pkg/bindings/play
parent5a746c08f753c2e1227fefdbf9527cddba00e2fa (diff)
downloadpodman-ac3bd4c3318d2e15680d7dd62e76f5f58db4d425.tar.gz
podman-ac3bd4c3318d2e15680d7dd62e76f5f58db4d425.tar.bz2
podman-ac3bd4c3318d2e15680d7dd62e76f5f58db4d425.zip
[NO TESTS NEEDED] Generated files
Signed-off-by: Matej Vasek <mvasek@redhat.com>
Diffstat (limited to 'pkg/bindings/play')
-rw-r--r--pkg/bindings/play/types_kube_options.go44
1 files changed, 17 insertions, 27 deletions
diff --git a/pkg/bindings/play/types_kube_options.go b/pkg/bindings/play/types_kube_options.go
index 5aec4b479..738bf5a28 100644
--- a/pkg/bindings/play/types_kube_options.go
+++ b/pkg/bindings/play/types_kube_options.go
@@ -1,13 +1,14 @@
package play
import (
+ "errors"
+ "fmt"
"net/url"
"reflect"
- "strconv"
"strings"
+ "github.com/containers/podman/v2/pkg/bindings/util"
jsoniter "github.com/json-iterator/go"
- "github.com/pkg/errors"
)
/*
@@ -43,33 +44,19 @@ func (o *KubeOptions) ToParams() (url.Values, error) {
if reflect.Ptr == f.Kind() {
f = f.Elem()
}
- switch f.Kind() {
- case reflect.Bool:
- params.Set(fieldName, strconv.FormatBool(f.Bool()))
- case reflect.String:
- params.Set(fieldName, f.String())
- case reflect.Int, reflect.Int64:
- // f.Int() is always an int64
- params.Set(fieldName, strconv.FormatInt(f.Int(), 10))
- case reflect.Uint, reflect.Uint64:
- // f.Uint() is always an uint64
- params.Set(fieldName, strconv.FormatUint(f.Uint(), 10))
- case reflect.Slice:
- typ := reflect.TypeOf(f.Interface()).Elem()
- switch typ.Kind() {
- case reflect.String:
- sl := f.Slice(0, f.Len())
- s, ok := sl.Interface().([]string)
- if !ok {
- return nil, errors.New("failed to convert to string slice")
+ switch {
+ case util.IsSimpleType(f):
+ params.Set(fieldName, util.SimpleTypeToParam(f))
+ case f.Kind() == reflect.Slice:
+ for i := 0; i < f.Len(); i++ {
+ elem := f.Index(i)
+ if util.IsSimpleType(elem) {
+ params.Add(fieldName, util.SimpleTypeToParam(elem))
+ } else {
+ return nil, errors.New("slices must contain only simple types")
}
- for _, val := range s {
- params.Add(fieldName, val)
- }
- default:
- return nil, errors.Errorf("unknown slice type %s", f.Kind().String())
}
- case reflect.Map:
+ case f.Kind() == reflect.Map:
lowerCaseKeys := make(map[string][]string)
iter := f.MapRange()
for iter.Next() {
@@ -82,7 +69,10 @@ func (o *KubeOptions) ToParams() (url.Values, error) {
}
params.Set(fieldName, s)
+ default:
+ panic(fmt.Sprintf("don't known how to handle %s", f.Type().String()))
}
+
}
return params, nil
}