diff options
author | Matej Vasek <mvasek@redhat.com> | 2021-02-10 15:38:34 +0100 |
---|---|---|
committer | Matej Vasek <mvasek@redhat.com> | 2021-02-14 15:44:22 +0100 |
commit | 6ffd05d0bd688f71b424ab2f62e7cc4df0e8e751 (patch) | |
tree | a4640b2b8799533fb31fbb78219941e1dd86efdb /pkg/bindings/images | |
parent | 1d15ed708f2d7c6dab5ee90415acb156973ac1a4 (diff) | |
download | podman-6ffd05d0bd688f71b424ab2f62e7cc4df0e8e751.tar.gz podman-6ffd05d0bd688f71b424ab2f62e7cc4df0e8e751.tar.bz2 podman-6ffd05d0bd688f71b424ab2f62e7cc4df0e8e751.zip |
[NO TESTS NEEDED] Refactor generated code
Extracted common functionality to util function.
Signed-off-by: Matej Vasek <mvasek@redhat.com>
Diffstat (limited to 'pkg/bindings/images')
-rw-r--r-- | pkg/bindings/images/types_diff_options.go | 56 | ||||
-rw-r--r-- | pkg/bindings/images/types_exists_options.go | 56 | ||||
-rw-r--r-- | pkg/bindings/images/types_export_options.go | 56 | ||||
-rw-r--r-- | pkg/bindings/images/types_get_options.go | 56 | ||||
-rw-r--r-- | pkg/bindings/images/types_history_options.go | 56 | ||||
-rw-r--r-- | pkg/bindings/images/types_import_options.go | 56 | ||||
-rw-r--r-- | pkg/bindings/images/types_list_options.go | 56 | ||||
-rw-r--r-- | pkg/bindings/images/types_load_options.go | 56 | ||||
-rw-r--r-- | pkg/bindings/images/types_prune_options.go | 56 | ||||
-rw-r--r-- | pkg/bindings/images/types_pull_options.go | 56 | ||||
-rw-r--r-- | pkg/bindings/images/types_push_options.go | 56 | ||||
-rw-r--r-- | pkg/bindings/images/types_remove_options.go | 56 | ||||
-rw-r--r-- | pkg/bindings/images/types_search_options.go | 56 | ||||
-rw-r--r-- | pkg/bindings/images/types_tag_options.go | 56 | ||||
-rw-r--r-- | pkg/bindings/images/types_tree_options.go | 56 | ||||
-rw-r--r-- | pkg/bindings/images/types_untag_options.go | 56 |
16 files changed, 32 insertions, 864 deletions
diff --git a/pkg/bindings/images/types_diff_options.go b/pkg/bindings/images/types_diff_options.go index 4f2bf0f6b..ae4b4655b 100644 --- a/pkg/bindings/images/types_diff_options.go +++ b/pkg/bindings/images/types_diff_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,58 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *DiffOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *DiffOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - 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") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/images/types_exists_options.go b/pkg/bindings/images/types_exists_options.go index 689c80902..9de1b9878 100644 --- a/pkg/bindings/images/types_exists_options.go +++ b/pkg/bindings/images/types_exists_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,58 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *ExistsOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *ExistsOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - 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") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/images/types_export_options.go b/pkg/bindings/images/types_export_options.go index 31361deb2..dcce565f6 100644 --- a/pkg/bindings/images/types_export_options.go +++ b/pkg/bindings/images/types_export_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *ExportOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *ExportOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - 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") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - } - return params, nil + return util.ToParams(o) } // WithCompress diff --git a/pkg/bindings/images/types_get_options.go b/pkg/bindings/images/types_get_options.go index 5eb178a74..b9d00d82c 100644 --- a/pkg/bindings/images/types_get_options.go +++ b/pkg/bindings/images/types_get_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *GetOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *GetOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - 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") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - } - return params, nil + return util.ToParams(o) } // WithSize diff --git a/pkg/bindings/images/types_history_options.go b/pkg/bindings/images/types_history_options.go index becabaa59..e2cd43852 100644 --- a/pkg/bindings/images/types_history_options.go +++ b/pkg/bindings/images/types_history_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,58 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *HistoryOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *HistoryOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - 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") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/images/types_import_options.go b/pkg/bindings/images/types_import_options.go index 6e9160b63..ff409cc7c 100644 --- a/pkg/bindings/images/types_import_options.go +++ b/pkg/bindings/images/types_import_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *ImportOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *ImportOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - 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") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - } - return params, nil + return util.ToParams(o) } // WithChanges diff --git a/pkg/bindings/images/types_list_options.go b/pkg/bindings/images/types_list_options.go index 12d186f6b..38d1bde70 100644 --- a/pkg/bindings/images/types_list_options.go +++ b/pkg/bindings/images/types_list_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *ListOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *ListOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - 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") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - } - return params, nil + return util.ToParams(o) } // WithAll diff --git a/pkg/bindings/images/types_load_options.go b/pkg/bindings/images/types_load_options.go index 913568937..d17e7cc10 100644 --- a/pkg/bindings/images/types_load_options.go +++ b/pkg/bindings/images/types_load_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *LoadOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *LoadOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - 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") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - } - return params, nil + return util.ToParams(o) } // WithReference diff --git a/pkg/bindings/images/types_prune_options.go b/pkg/bindings/images/types_prune_options.go index dad83dd2f..deef211c1 100644 --- a/pkg/bindings/images/types_prune_options.go +++ b/pkg/bindings/images/types_prune_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *PruneOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *PruneOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - 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") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - } - return params, nil + return util.ToParams(o) } // WithAll diff --git a/pkg/bindings/images/types_pull_options.go b/pkg/bindings/images/types_pull_options.go index c3c7a3dc4..2220ade26 100644 --- a/pkg/bindings/images/types_pull_options.go +++ b/pkg/bindings/images/types_pull_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *PullOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *PullOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - 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") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - } - return params, nil + return util.ToParams(o) } // WithAllTags diff --git a/pkg/bindings/images/types_push_options.go b/pkg/bindings/images/types_push_options.go index 26a8d7e91..be14e7d78 100644 --- a/pkg/bindings/images/types_push_options.go +++ b/pkg/bindings/images/types_push_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *PushOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *PushOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - 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") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - } - return params, nil + return util.ToParams(o) } // WithAll diff --git a/pkg/bindings/images/types_remove_options.go b/pkg/bindings/images/types_remove_options.go index fba4f63b6..964fca265 100644 --- a/pkg/bindings/images/types_remove_options.go +++ b/pkg/bindings/images/types_remove_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *RemoveOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *RemoveOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - 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") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - } - return params, nil + return util.ToParams(o) } // WithAll diff --git a/pkg/bindings/images/types_search_options.go b/pkg/bindings/images/types_search_options.go index 812a9abd3..1321d1910 100644 --- a/pkg/bindings/images/types_search_options.go +++ b/pkg/bindings/images/types_search_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *SearchOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *SearchOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - 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") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - } - return params, nil + return util.ToParams(o) } // WithAuthfile diff --git a/pkg/bindings/images/types_tag_options.go b/pkg/bindings/images/types_tag_options.go index e1217a9aa..74977e10a 100644 --- a/pkg/bindings/images/types_tag_options.go +++ b/pkg/bindings/images/types_tag_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,58 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *TagOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *TagOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - 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") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - } - return params, nil + return util.ToParams(o) } diff --git a/pkg/bindings/images/types_tree_options.go b/pkg/bindings/images/types_tree_options.go index 0a574ffc1..a07a3a647 100644 --- a/pkg/bindings/images/types_tree_options.go +++ b/pkg/bindings/images/types_tree_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,60 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *TreeOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *TreeOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - 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") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - } - return params, nil + return util.ToParams(o) } // WithWhatRequires diff --git a/pkg/bindings/images/types_untag_options.go b/pkg/bindings/images/types_untag_options.go index ced84876e..3f7ac4a5a 100644 --- a/pkg/bindings/images/types_untag_options.go +++ b/pkg/bindings/images/types_untag_options.go @@ -2,12 +2,8 @@ package images import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -16,58 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *UntagOptions) Changed(fieldName string) bool { - r := reflect.ValueOf(o) - value := reflect.Indirect(r).FieldByName(fieldName) - return !value.IsNil() + return util.Changed(o, fieldName) } // ToParams func (o *UntagOptions) ToParams() (url.Values, error) { - params := url.Values{} - if o == nil { - return params, nil - } - json := jsoniter.ConfigCompatibleWithStandardLibrary - s := reflect.ValueOf(o) - if reflect.Ptr == s.Kind() { - s = s.Elem() - } - sType := s.Type() - for i := 0; i < s.NumField(); i++ { - fieldName := sType.Field(i).Name - if !o.Changed(fieldName) { - continue - } - fieldName = strings.ToLower(fieldName) - f := s.Field(i) - if reflect.Ptr == f.Kind() { - f = f.Elem() - } - 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") - } - } - case f.Kind() == reflect.Map: - lowerCaseKeys := make(map[string][]string) - iter := f.MapRange() - for iter.Next() { - lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) - } - s, err := json.MarshalToString(lowerCaseKeys) - if err != nil { - return nil, err - } - - params.Set(fieldName, s) - } - } - return params, nil + return util.ToParams(o) } |