Skip to content

Commit

Permalink
Merge pull request #9203 from matejvasek/improve_param_serder_generator
Browse files Browse the repository at this point in the history
[NO TESTS NEEDED] Improve binding generator
  • Loading branch information
openshift-merge-robot authored Feb 3, 2021
2 parents d1e0afd + bde23a0 commit 881f3d7
Show file tree
Hide file tree
Showing 92 changed files with 1,221 additions and 2,374 deletions.
39 changes: 13 additions & 26 deletions pkg/bindings/containers/types_attach_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package containers
import (
"net/url"
"reflect"
"strconv"
"strings"

"github.com/containers/podman/v2/pkg/bindings/util"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -43,33 +43,19 @@ func (o *AttachOptions) 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() {
Expand All @@ -83,6 +69,7 @@ func (o *AttachOptions) ToParams() (url.Values, error) {

params.Set(fieldName, s)
}

}
return params, nil
}
Expand Down
39 changes: 13 additions & 26 deletions pkg/bindings/containers/types_checkpoint_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package containers
import (
"net/url"
"reflect"
"strconv"
"strings"

"github.com/containers/podman/v2/pkg/bindings/util"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -43,33 +43,19 @@ func (o *CheckpointOptions) 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() {
Expand All @@ -83,6 +69,7 @@ func (o *CheckpointOptions) ToParams() (url.Values, error) {

params.Set(fieldName, s)
}

}
return params, nil
}
Expand Down
39 changes: 13 additions & 26 deletions pkg/bindings/containers/types_commit_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package containers
import (
"net/url"
"reflect"
"strconv"
"strings"

"github.com/containers/podman/v2/pkg/bindings/util"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -43,33 +43,19 @@ func (o *CommitOptions) 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() {
Expand All @@ -83,6 +69,7 @@ func (o *CommitOptions) ToParams() (url.Values, error) {

params.Set(fieldName, s)
}

}
return params, nil
}
Expand Down
39 changes: 13 additions & 26 deletions pkg/bindings/containers/types_create_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package containers
import (
"net/url"
"reflect"
"strconv"
"strings"

"github.com/containers/podman/v2/pkg/bindings/util"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -43,33 +43,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() {
Expand All @@ -83,6 +69,7 @@ func (o *CreateOptions) ToParams() (url.Values, error) {

params.Set(fieldName, s)
}

}
return params, nil
}
39 changes: 13 additions & 26 deletions pkg/bindings/containers/types_diff_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package containers
import (
"net/url"
"reflect"
"strconv"
"strings"

"github.com/containers/podman/v2/pkg/bindings/util"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -43,33 +43,19 @@ func (o *DiffOptions) 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() {
Expand All @@ -83,6 +69,7 @@ func (o *DiffOptions) ToParams() (url.Values, error) {

params.Set(fieldName, s)
}

}
return params, nil
}
39 changes: 13 additions & 26 deletions pkg/bindings/containers/types_execinspect_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package containers
import (
"net/url"
"reflect"
"strconv"
"strings"

"github.com/containers/podman/v2/pkg/bindings/util"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -43,33 +43,19 @@ func (o *ExecInspectOptions) 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() {
Expand All @@ -83,6 +69,7 @@ func (o *ExecInspectOptions) ToParams() (url.Values, error) {

params.Set(fieldName, s)
}

}
return params, nil
}
Loading

0 comments on commit 881f3d7

Please sign in to comment.