diff options
author | Matej Vasek <mvasek@redhat.com> | 2021-02-02 19:36:55 +0100 |
---|---|---|
committer | Matej Vasek <mvasek@redhat.com> | 2021-02-02 19:49:41 +0100 |
commit | ac3bd4c3318d2e15680d7dd62e76f5f58db4d425 (patch) | |
tree | 6b00be188d8083374a3f13ae7b2a7c6d4f265611 /pkg/bindings/manifests | |
parent | 5a746c08f753c2e1227fefdbf9527cddba00e2fa (diff) | |
download | podman-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/manifests')
-rw-r--r-- | pkg/bindings/manifests/types_add_options.go | 44 | ||||
-rw-r--r-- | pkg/bindings/manifests/types_create_options.go | 44 | ||||
-rw-r--r-- | pkg/bindings/manifests/types_exists_options.go | 44 | ||||
-rw-r--r-- | pkg/bindings/manifests/types_inspect_options.go | 44 | ||||
-rw-r--r-- | pkg/bindings/manifests/types_remove_options.go | 44 |
5 files changed, 85 insertions, 135 deletions
diff --git a/pkg/bindings/manifests/types_add_options.go b/pkg/bindings/manifests/types_add_options.go index 1e588c668..049419dda 100644 --- a/pkg/bindings/manifests/types_add_options.go +++ b/pkg/bindings/manifests/types_add_options.go @@ -1,13 +1,14 @@ package manifests 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 *AddOptions) 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 *AddOptions) 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 } diff --git a/pkg/bindings/manifests/types_create_options.go b/pkg/bindings/manifests/types_create_options.go index 3a564a92b..c5c55075d 100644 --- a/pkg/bindings/manifests/types_create_options.go +++ b/pkg/bindings/manifests/types_create_options.go @@ -1,13 +1,14 @@ package manifests 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 *CreateOptions) 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 *CreateOptions) 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 } diff --git a/pkg/bindings/manifests/types_exists_options.go b/pkg/bindings/manifests/types_exists_options.go index fd2cd3ee9..06e0cf13b 100644 --- a/pkg/bindings/manifests/types_exists_options.go +++ b/pkg/bindings/manifests/types_exists_options.go @@ -1,13 +1,14 @@ package manifests 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 *ExistsOptions) 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 *ExistsOptions) 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 } diff --git a/pkg/bindings/manifests/types_inspect_options.go b/pkg/bindings/manifests/types_inspect_options.go index 2af4190d4..efcf70b5f 100644 --- a/pkg/bindings/manifests/types_inspect_options.go +++ b/pkg/bindings/manifests/types_inspect_options.go @@ -1,13 +1,14 @@ package manifests 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 *InspectOptions) 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 *InspectOptions) 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 } diff --git a/pkg/bindings/manifests/types_remove_options.go b/pkg/bindings/manifests/types_remove_options.go index 3b35c38b8..48264dd1c 100644 --- a/pkg/bindings/manifests/types_remove_options.go +++ b/pkg/bindings/manifests/types_remove_options.go @@ -1,13 +1,14 @@ package manifests 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 *RemoveOptions) 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 *RemoveOptions) 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 } |