diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-02-03 04:59:23 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-03 04:59:23 -0500 |
commit | 881f3d788d48b683e674d1f9778d581370c9c11e (patch) | |
tree | a05094ec7a8ebee7007b734b1bd73b13ba42c1f6 /pkg/bindings/network | |
parent | d1e0afdd47c1868ce0d22e48ae9b0b9d89ba6274 (diff) | |
parent | bde23a0219729e530895153b12d5578e9f02dab8 (diff) | |
download | podman-881f3d788d48b683e674d1f9778d581370c9c11e.tar.gz podman-881f3d788d48b683e674d1f9778d581370c9c11e.tar.bz2 podman-881f3d788d48b683e674d1f9778d581370c9c11e.zip |
Merge pull request #9203 from matejvasek/improve_param_serder_generator
[NO TESTS NEEDED] Improve binding generator
Diffstat (limited to 'pkg/bindings/network')
-rw-r--r-- | pkg/bindings/network/types_connect_options.go | 39 | ||||
-rw-r--r-- | pkg/bindings/network/types_create_options.go | 39 | ||||
-rw-r--r-- | pkg/bindings/network/types_disconnect_options.go | 39 | ||||
-rw-r--r-- | pkg/bindings/network/types_exists_options.go | 39 | ||||
-rw-r--r-- | pkg/bindings/network/types_inspect_options.go | 39 | ||||
-rw-r--r-- | pkg/bindings/network/types_list_options.go | 39 | ||||
-rw-r--r-- | pkg/bindings/network/types_remove_options.go | 39 |
7 files changed, 91 insertions, 182 deletions
diff --git a/pkg/bindings/network/types_connect_options.go b/pkg/bindings/network/types_connect_options.go index b6081ba57..4440bbed4 100644 --- a/pkg/bindings/network/types_connect_options.go +++ b/pkg/bindings/network/types_connect_options.go @@ -3,9 +3,9 @@ package network import ( "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 +43,19 @@ func (o *ConnectOptions) 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() { @@ -83,6 +69,7 @@ func (o *ConnectOptions) ToParams() (url.Values, error) { params.Set(fieldName, s) } + } return params, nil } diff --git a/pkg/bindings/network/types_create_options.go b/pkg/bindings/network/types_create_options.go index 5b0abe870..5fbdce93a 100644 --- a/pkg/bindings/network/types_create_options.go +++ b/pkg/bindings/network/types_create_options.go @@ -4,9 +4,9 @@ import ( "net" "net/url" "reflect" - "strconv" "strings" + "github.com/containers/podman/v2/pkg/bindings/util" jsoniter "github.com/json-iterator/go" "github.com/pkg/errors" ) @@ -44,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() { @@ -84,6 +70,7 @@ func (o *CreateOptions) ToParams() (url.Values, error) { params.Set(fieldName, s) } + } return params, nil } diff --git a/pkg/bindings/network/types_disconnect_options.go b/pkg/bindings/network/types_disconnect_options.go index 8b2a9cb71..947f2f114 100644 --- a/pkg/bindings/network/types_disconnect_options.go +++ b/pkg/bindings/network/types_disconnect_options.go @@ -3,9 +3,9 @@ package network import ( "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 +43,19 @@ func (o *DisconnectOptions) 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() { @@ -83,6 +69,7 @@ func (o *DisconnectOptions) ToParams() (url.Values, error) { params.Set(fieldName, s) } + } return params, nil } diff --git a/pkg/bindings/network/types_exists_options.go b/pkg/bindings/network/types_exists_options.go index 8076a18e8..2fad34789 100644 --- a/pkg/bindings/network/types_exists_options.go +++ b/pkg/bindings/network/types_exists_options.go @@ -3,9 +3,9 @@ package network import ( "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 +43,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() { @@ -83,6 +69,7 @@ func (o *ExistsOptions) ToParams() (url.Values, error) { params.Set(fieldName, s) } + } return params, nil } diff --git a/pkg/bindings/network/types_inspect_options.go b/pkg/bindings/network/types_inspect_options.go index cec5ef7b2..144ccbfae 100644 --- a/pkg/bindings/network/types_inspect_options.go +++ b/pkg/bindings/network/types_inspect_options.go @@ -3,9 +3,9 @@ package network import ( "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 +43,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() { @@ -83,6 +69,7 @@ func (o *InspectOptions) ToParams() (url.Values, error) { params.Set(fieldName, s) } + } return params, nil } diff --git a/pkg/bindings/network/types_list_options.go b/pkg/bindings/network/types_list_options.go index 6a33fb7b6..60632ce33 100644 --- a/pkg/bindings/network/types_list_options.go +++ b/pkg/bindings/network/types_list_options.go @@ -3,9 +3,9 @@ package network import ( "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 +43,19 @@ func (o *ListOptions) 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() { @@ -83,6 +69,7 @@ func (o *ListOptions) ToParams() (url.Values, error) { params.Set(fieldName, s) } + } return params, nil } diff --git a/pkg/bindings/network/types_remove_options.go b/pkg/bindings/network/types_remove_options.go index 861fe1f2c..4ad4a2301 100644 --- a/pkg/bindings/network/types_remove_options.go +++ b/pkg/bindings/network/types_remove_options.go @@ -3,9 +3,9 @@ package network import ( "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 +43,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() { @@ -83,6 +69,7 @@ func (o *RemoveOptions) ToParams() (url.Values, error) { params.Set(fieldName, s) } + } return params, nil } |