diff options
Diffstat (limited to 'pkg')
97 files changed, 279 insertions, 5211 deletions
diff --git a/pkg/bindings/containers/types_attach_options.go b/pkg/bindings/containers/types_attach_options.go index 88ade89b4..e806d161b 100644 --- a/pkg/bindings/containers/types_attach_options.go +++ b/pkg/bindings/containers/types_attach_options.go @@ -2,12 +2,8 @@ package containers 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 *AttachOptions) 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 *AttachOptions) 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) } // WithDetachKeys diff --git a/pkg/bindings/containers/types_checkpoint_options.go b/pkg/bindings/containers/types_checkpoint_options.go index 002a08e00..edac04ec4 100644 --- a/pkg/bindings/containers/types_checkpoint_options.go +++ b/pkg/bindings/containers/types_checkpoint_options.go @@ -2,12 +2,8 @@ package containers 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 *CheckpointOptions) 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 *CheckpointOptions) 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) } // WithExport diff --git a/pkg/bindings/containers/types_commit_options.go b/pkg/bindings/containers/types_commit_options.go index 006fe7ae7..f3e0a16fc 100644 --- a/pkg/bindings/containers/types_commit_options.go +++ b/pkg/bindings/containers/types_commit_options.go @@ -2,12 +2,8 @@ package containers 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 *CommitOptions) 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 *CommitOptions) 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) } // WithAuthor diff --git a/pkg/bindings/containers/types_create_options.go b/pkg/bindings/containers/types_create_options.go index 914a6ed3e..4ef3be2b4 100644 --- a/pkg/bindings/containers/types_create_options.go +++ b/pkg/bindings/containers/types_create_options.go @@ -2,12 +2,8 @@ package containers 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 *CreateOptions) 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 *CreateOptions) 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/containers/types_diff_options.go b/pkg/bindings/containers/types_diff_options.go index ebf3a7ad8..952e149e9 100644 --- a/pkg/bindings/containers/types_diff_options.go +++ b/pkg/bindings/containers/types_diff_options.go @@ -2,12 +2,8 @@ package containers 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/containers/types_execinspect_options.go b/pkg/bindings/containers/types_execinspect_options.go index 772318cd3..2ceb41878 100644 --- a/pkg/bindings/containers/types_execinspect_options.go +++ b/pkg/bindings/containers/types_execinspect_options.go @@ -2,12 +2,8 @@ package containers 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 *ExecInspectOptions) 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 *ExecInspectOptions) 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/containers/types_execstart_options.go b/pkg/bindings/containers/types_execstart_options.go index 9a032d200..e5b73bc7b 100644 --- a/pkg/bindings/containers/types_execstart_options.go +++ b/pkg/bindings/containers/types_execstart_options.go @@ -2,12 +2,8 @@ package containers 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 *ExecStartOptions) 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 *ExecStartOptions) 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/containers/types_execstartandattach_options.go b/pkg/bindings/containers/types_execstartandattach_options.go index 6bc288de3..1b9276c8c 100644 --- a/pkg/bindings/containers/types_execstartandattach_options.go +++ b/pkg/bindings/containers/types_execstartandattach_options.go @@ -4,12 +4,8 @@ import ( "bufio" "io" "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -18,60 +14,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *ExecStartAndAttachOptions) 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 *ExecStartAndAttachOptions) 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) } // WithOutputStream diff --git a/pkg/bindings/containers/types_exists_options.go b/pkg/bindings/containers/types_exists_options.go index 6a9086c78..ee822ab88 100644 --- a/pkg/bindings/containers/types_exists_options.go +++ b/pkg/bindings/containers/types_exists_options.go @@ -2,12 +2,8 @@ package containers 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 *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) } // WithExternal diff --git a/pkg/bindings/containers/types_export_options.go b/pkg/bindings/containers/types_export_options.go index 595d2cf87..03eac2bad 100644 --- a/pkg/bindings/containers/types_export_options.go +++ b/pkg/bindings/containers/types_export_options.go @@ -2,12 +2,8 @@ package containers 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 *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) } diff --git a/pkg/bindings/containers/types_healthcheck_options.go b/pkg/bindings/containers/types_healthcheck_options.go index 3e2b445af..ac6d67f63 100644 --- a/pkg/bindings/containers/types_healthcheck_options.go +++ b/pkg/bindings/containers/types_healthcheck_options.go @@ -2,12 +2,8 @@ package containers 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 *HealthCheckOptions) 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 *HealthCheckOptions) 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/containers/types_init_options.go b/pkg/bindings/containers/types_init_options.go index 5a107435e..7365bcd25 100644 --- a/pkg/bindings/containers/types_init_options.go +++ b/pkg/bindings/containers/types_init_options.go @@ -2,12 +2,8 @@ package containers 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 *InitOptions) 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 *InitOptions) 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/containers/types_inspect_options.go b/pkg/bindings/containers/types_inspect_options.go index 347521488..fb3e70a9d 100644 --- a/pkg/bindings/containers/types_inspect_options.go +++ b/pkg/bindings/containers/types_inspect_options.go @@ -2,12 +2,8 @@ package containers 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 *InspectOptions) 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 *InspectOptions) 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/containers/types_kill_options.go b/pkg/bindings/containers/types_kill_options.go index 0fdbef2f1..5acb0c67d 100644 --- a/pkg/bindings/containers/types_kill_options.go +++ b/pkg/bindings/containers/types_kill_options.go @@ -2,12 +2,8 @@ package containers 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 *KillOptions) 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 *KillOptions) 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) } // WithSignal diff --git a/pkg/bindings/containers/types_list_options.go b/pkg/bindings/containers/types_list_options.go index 51ae98dac..8e872c99e 100644 --- a/pkg/bindings/containers/types_list_options.go +++ b/pkg/bindings/containers/types_list_options.go @@ -2,12 +2,8 @@ package containers 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/containers/types_log_options.go b/pkg/bindings/containers/types_log_options.go index 51e01f1b4..a69570d0e 100644 --- a/pkg/bindings/containers/types_log_options.go +++ b/pkg/bindings/containers/types_log_options.go @@ -2,12 +2,8 @@ package containers 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 *LogOptions) 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 *LogOptions) 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) } // WithFollow diff --git a/pkg/bindings/containers/types_mount_options.go b/pkg/bindings/containers/types_mount_options.go index 0fa028e72..e5cc35307 100644 --- a/pkg/bindings/containers/types_mount_options.go +++ b/pkg/bindings/containers/types_mount_options.go @@ -2,12 +2,8 @@ package containers 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 *MountOptions) 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 *MountOptions) 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/containers/types_mountedcontainerpaths_options.go b/pkg/bindings/containers/types_mountedcontainerpaths_options.go index abfe9d95e..f0536abaa 100644 --- a/pkg/bindings/containers/types_mountedcontainerpaths_options.go +++ b/pkg/bindings/containers/types_mountedcontainerpaths_options.go @@ -2,12 +2,8 @@ package containers 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 *MountedContainerPathsOptions) 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 *MountedContainerPathsOptions) 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/containers/types_pause_options.go b/pkg/bindings/containers/types_pause_options.go index 5f15035d9..8497a24a8 100644 --- a/pkg/bindings/containers/types_pause_options.go +++ b/pkg/bindings/containers/types_pause_options.go @@ -2,12 +2,8 @@ package containers 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 *PauseOptions) 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 *PauseOptions) 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/containers/types_prune_options.go b/pkg/bindings/containers/types_prune_options.go index 99a85584e..2ea963c97 100644 --- a/pkg/bindings/containers/types_prune_options.go +++ b/pkg/bindings/containers/types_prune_options.go @@ -2,12 +2,8 @@ package containers 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) } // WithFilters diff --git a/pkg/bindings/containers/types_remove_options.go b/pkg/bindings/containers/types_remove_options.go index 99947f607..b9dea71a1 100644 --- a/pkg/bindings/containers/types_remove_options.go +++ b/pkg/bindings/containers/types_remove_options.go @@ -2,12 +2,8 @@ package containers 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) } // WithIgnore diff --git a/pkg/bindings/containers/types_rename_options.go b/pkg/bindings/containers/types_rename_options.go index 05d7138cd..c148f6730 100644 --- a/pkg/bindings/containers/types_rename_options.go +++ b/pkg/bindings/containers/types_rename_options.go @@ -2,12 +2,8 @@ package containers 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 *RenameOptions) 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 *RenameOptions) 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) } // WithName diff --git a/pkg/bindings/containers/types_resizeexectty_options.go b/pkg/bindings/containers/types_resizeexectty_options.go index 554d6fb85..256e5299b 100644 --- a/pkg/bindings/containers/types_resizeexectty_options.go +++ b/pkg/bindings/containers/types_resizeexectty_options.go @@ -2,12 +2,8 @@ package containers 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 *ResizeExecTTYOptions) 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 *ResizeExecTTYOptions) 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) } // WithHeight diff --git a/pkg/bindings/containers/types_resizetty_options.go b/pkg/bindings/containers/types_resizetty_options.go index a018993eb..4f2958ba0 100644 --- a/pkg/bindings/containers/types_resizetty_options.go +++ b/pkg/bindings/containers/types_resizetty_options.go @@ -2,12 +2,8 @@ package containers 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 *ResizeTTYOptions) 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 *ResizeTTYOptions) 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) } // WithHeight diff --git a/pkg/bindings/containers/types_restart_options.go b/pkg/bindings/containers/types_restart_options.go index fa1019a1f..8c791ae67 100644 --- a/pkg/bindings/containers/types_restart_options.go +++ b/pkg/bindings/containers/types_restart_options.go @@ -2,12 +2,8 @@ package containers 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 *RestartOptions) 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 *RestartOptions) 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) } // WithTimeout diff --git a/pkg/bindings/containers/types_restore_options.go b/pkg/bindings/containers/types_restore_options.go index 793222af3..e0204a677 100644 --- a/pkg/bindings/containers/types_restore_options.go +++ b/pkg/bindings/containers/types_restore_options.go @@ -2,12 +2,8 @@ package containers 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 *RestoreOptions) 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 *RestoreOptions) 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) } // WithIgnoreRootfs diff --git a/pkg/bindings/containers/types_shouldrestart_options.go b/pkg/bindings/containers/types_shouldrestart_options.go index e9585dc61..b0aeff09c 100644 --- a/pkg/bindings/containers/types_shouldrestart_options.go +++ b/pkg/bindings/containers/types_shouldrestart_options.go @@ -2,12 +2,8 @@ package containers 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 *ShouldRestartOptions) 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 *ShouldRestartOptions) 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/containers/types_start_options.go b/pkg/bindings/containers/types_start_options.go index 0ca2ee832..60e061c79 100644 --- a/pkg/bindings/containers/types_start_options.go +++ b/pkg/bindings/containers/types_start_options.go @@ -2,12 +2,8 @@ package containers 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 *StartOptions) 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 *StartOptions) 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) } // WithDetachKeys diff --git a/pkg/bindings/containers/types_stats_options.go b/pkg/bindings/containers/types_stats_options.go index 1ecd99536..ce0fdfe87 100644 --- a/pkg/bindings/containers/types_stats_options.go +++ b/pkg/bindings/containers/types_stats_options.go @@ -2,12 +2,8 @@ package containers 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 *StatsOptions) 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 *StatsOptions) 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) } // WithStream diff --git a/pkg/bindings/containers/types_stop_options.go b/pkg/bindings/containers/types_stop_options.go index fcc5b1be8..14ece3a43 100644 --- a/pkg/bindings/containers/types_stop_options.go +++ b/pkg/bindings/containers/types_stop_options.go @@ -2,12 +2,8 @@ package containers 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 *StopOptions) 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 *StopOptions) 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) } // WithIgnore diff --git a/pkg/bindings/containers/types_top_options.go b/pkg/bindings/containers/types_top_options.go index 2f04a2069..0481abe9a 100644 --- a/pkg/bindings/containers/types_top_options.go +++ b/pkg/bindings/containers/types_top_options.go @@ -2,12 +2,8 @@ package containers 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 *TopOptions) 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 *TopOptions) 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) } // WithDescriptors diff --git a/pkg/bindings/containers/types_unmount_options.go b/pkg/bindings/containers/types_unmount_options.go index ede1dbdc7..c32747e3a 100644 --- a/pkg/bindings/containers/types_unmount_options.go +++ b/pkg/bindings/containers/types_unmount_options.go @@ -2,12 +2,8 @@ package containers 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 *UnmountOptions) 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 *UnmountOptions) 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/containers/types_unpause_options.go b/pkg/bindings/containers/types_unpause_options.go index 0004219bf..5f17067af 100644 --- a/pkg/bindings/containers/types_unpause_options.go +++ b/pkg/bindings/containers/types_unpause_options.go @@ -2,12 +2,8 @@ package containers 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 *UnpauseOptions) 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 *UnpauseOptions) 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/containers/types_wait_options.go b/pkg/bindings/containers/types_wait_options.go index 7ff6fc6f0..42ee0c316 100644 --- a/pkg/bindings/containers/types_wait_options.go +++ b/pkg/bindings/containers/types_wait_options.go @@ -2,13 +2,9 @@ package containers import ( "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/libpod/define" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -17,60 +13,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *WaitOptions) 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 *WaitOptions) 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) } // WithCondition diff --git a/pkg/bindings/generate/types_kube_options.go b/pkg/bindings/generate/types_kube_options.go index 7d7b5d335..5d34f4bee 100644 --- a/pkg/bindings/generate/types_kube_options.go +++ b/pkg/bindings/generate/types_kube_options.go @@ -1,13 +1,9 @@ package generate import ( - "errors" "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" ) /* @@ -16,60 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *KubeOptions) 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 *KubeOptions) 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) } // WithService diff --git a/pkg/bindings/generate/types_systemd_options.go b/pkg/bindings/generate/types_systemd_options.go index 132904cf1..dc7378888 100644 --- a/pkg/bindings/generate/types_systemd_options.go +++ b/pkg/bindings/generate/types_systemd_options.go @@ -1,13 +1,9 @@ package generate import ( - "errors" "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" ) /* @@ -16,60 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *SystemdOptions) 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 *SystemdOptions) 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) } // WithUseName diff --git a/pkg/bindings/generator/generator.go b/pkg/bindings/generator/generator.go index f65d136ea..fc06fedd9 100644 --- a/pkg/bindings/generator/generator.go +++ b/pkg/bindings/generator/generator.go @@ -27,79 +27,31 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *{{.StructName}}) 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 *{{.StructName}}) 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) } -` -var fieldTmpl = ` +{{range $field := .Fields}} // With{{.Name}} -func(o *{{.StructName}}) With{{.Name}}(value {{.Type}}) *{{.StructName}} { - v := {{.TypedValue}} - o.{{.Name}} = v +func(o *{{$field.StructName}}) With{{$field.Name}}(value {{$field.Type}}) *{{$field.StructName}} { + v := {{$field.TypedValue}} + o.{{$field.Name}} = v return o } // Get{{.Name}} -func(o *{{.StructName}}) Get{{.Name}}() {{.Type}} { - var {{.ZeroName}} {{.Type}} - if o.{{.Name}} == nil { - return {{.ZeroName}} +func(o *{{$field.StructName}}) Get{{$field.Name}}() {{$field.Type}} { + var {{$field.ZeroName}} {{$field.Type}} + if o.{{$field.Name}} == nil { + return {{$field.ZeroName}} } - return {{.TypedName}} + return {{$field.TypedName}} } +{{end}} ` type fieldStruct struct { @@ -143,20 +95,7 @@ func main() { out.Close() } }() - bodyStruct := struct { - PackageName string - Imports []string - Date string - StructName string - }{ - PackageName: pkg, - Imports: imports, - Date: time.Now().String(), - StructName: inputStructName, - } - body := template.Must(template.New("body").Parse(bodyTmpl)) - fields := template.Must(template.New("fields").Parse(fieldTmpl)) ast.Inspect(f, func(n ast.Node) bool { ref, refOK := n.(*ast.TypeSpec) if refOK { @@ -200,20 +139,28 @@ func main() { fieldStructs = append(fieldStructs, fStruct) } // for + bodyStruct := struct { + PackageName string + Imports []string + Date string + StructName string + Fields []fieldStruct + }{ + PackageName: pkg, + Imports: imports, + Date: time.Now().String(), + StructName: inputStructName, + Fields: fieldStructs, + } + + body := template.Must(template.New("body").Parse(bodyTmpl)) + // create the body if err := body.Execute(out, bodyStruct); err != nil { fmt.Println(err) os.Exit(1) } - // create with func from the struct fields - for _, fs := range fieldStructs { - if err := fields.Execute(out, fs); err != nil { - fmt.Println(err) - os.Exit(1) - } - } - // close out file if err := out.Close(); err != nil { fmt.Println(err) 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) } diff --git a/pkg/bindings/manifests/types_add_options.go b/pkg/bindings/manifests/types_add_options.go index 8947b1286..ae7e914b2 100644 --- a/pkg/bindings/manifests/types_add_options.go +++ b/pkg/bindings/manifests/types_add_options.go @@ -1,13 +1,9 @@ package manifests import ( - "errors" "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" ) /* @@ -16,60 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *AddOptions) 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 *AddOptions) 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/manifests/types_create_options.go b/pkg/bindings/manifests/types_create_options.go index ee8b56df7..a8e11b828 100644 --- a/pkg/bindings/manifests/types_create_options.go +++ b/pkg/bindings/manifests/types_create_options.go @@ -1,13 +1,9 @@ package manifests import ( - "errors" "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" ) /* @@ -16,60 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *CreateOptions) 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 *CreateOptions) 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/manifests/types_exists_options.go b/pkg/bindings/manifests/types_exists_options.go index 16527660c..df202f677 100644 --- a/pkg/bindings/manifests/types_exists_options.go +++ b/pkg/bindings/manifests/types_exists_options.go @@ -1,13 +1,9 @@ package manifests import ( - "errors" "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" ) /* @@ -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/manifests/types_inspect_options.go b/pkg/bindings/manifests/types_inspect_options.go index a2a40e6a4..90be7ebe3 100644 --- a/pkg/bindings/manifests/types_inspect_options.go +++ b/pkg/bindings/manifests/types_inspect_options.go @@ -1,13 +1,9 @@ package manifests import ( - "errors" "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" ) /* @@ -16,58 +12,10 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *InspectOptions) 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 *InspectOptions) 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/manifests/types_remove_options.go b/pkg/bindings/manifests/types_remove_options.go index d3cac775e..612d72dac 100644 --- a/pkg/bindings/manifests/types_remove_options.go +++ b/pkg/bindings/manifests/types_remove_options.go @@ -1,13 +1,9 @@ package manifests import ( - "errors" "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" ) /* @@ -16,58 +12,10 @@ 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) } diff --git a/pkg/bindings/network/types_connect_options.go b/pkg/bindings/network/types_connect_options.go index 930fb5531..b3cad6164 100644 --- a/pkg/bindings/network/types_connect_options.go +++ b/pkg/bindings/network/types_connect_options.go @@ -2,12 +2,8 @@ package network 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 *ConnectOptions) 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 *ConnectOptions) 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) } // WithAliases diff --git a/pkg/bindings/network/types_create_options.go b/pkg/bindings/network/types_create_options.go index 4b4afc4a8..553c94ee5 100644 --- a/pkg/bindings/network/types_create_options.go +++ b/pkg/bindings/network/types_create_options.go @@ -3,12 +3,8 @@ package network import ( "net" "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" - "github.com/pkg/errors" ) /* @@ -17,60 +13,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *CreateOptions) 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 *CreateOptions) 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) } // WithDisableDNS diff --git a/pkg/bindings/network/types_disconnect_options.go b/pkg/bindings/network/types_disconnect_options.go index cbcea8f7e..667da0d99 100644 --- a/pkg/bindings/network/types_disconnect_options.go +++ b/pkg/bindings/network/types_disconnect_options.go @@ -2,12 +2,8 @@ package network 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 *DisconnectOptions) 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 *DisconnectOptions) 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) } // WithForce diff --git a/pkg/bindings/network/types_exists_options.go b/pkg/bindings/network/types_exists_options.go index 0de2a00b5..4038c091a 100644 --- a/pkg/bindings/network/types_exists_options.go +++ b/pkg/bindings/network/types_exists_options.go @@ -2,12 +2,8 @@ package network 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/network/types_inspect_options.go b/pkg/bindings/network/types_inspect_options.go index 3c69b37ec..ce8f58e2e 100644 --- a/pkg/bindings/network/types_inspect_options.go +++ b/pkg/bindings/network/types_inspect_options.go @@ -2,12 +2,8 @@ package network 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 *InspectOptions) 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 *InspectOptions) 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/network/types_list_options.go b/pkg/bindings/network/types_list_options.go index e00430809..c16e4c05e 100644 --- a/pkg/bindings/network/types_list_options.go +++ b/pkg/bindings/network/types_list_options.go @@ -2,12 +2,8 @@ package network 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) } // WithFilters diff --git a/pkg/bindings/network/types_prune_options.go b/pkg/bindings/network/types_prune_options.go index f9685a225..c3299835f 100644 --- a/pkg/bindings/network/types_prune_options.go +++ b/pkg/bindings/network/types_prune_options.go @@ -2,12 +2,8 @@ package network 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 *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) } diff --git a/pkg/bindings/network/types_remove_options.go b/pkg/bindings/network/types_remove_options.go index f42f6c256..8e4dca819 100644 --- a/pkg/bindings/network/types_remove_options.go +++ b/pkg/bindings/network/types_remove_options.go @@ -2,12 +2,8 @@ package network 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) } // WithForce diff --git a/pkg/bindings/play/types_kube_options.go b/pkg/bindings/play/types_kube_options.go index 649522908..946c19b28 100644 --- a/pkg/bindings/play/types_kube_options.go +++ b/pkg/bindings/play/types_kube_options.go @@ -1,13 +1,9 @@ package play import ( - "errors" "net/url" - "reflect" - "strings" "github.com/containers/podman/v2/pkg/bindings/util" - jsoniter "github.com/json-iterator/go" ) /* @@ -16,60 +12,12 @@ This file is generated automatically by go generate. Do not edit. // Changed func (o *KubeOptions) 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 *KubeOptions) 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/pods/types_create_options.go b/pkg/bindings/pods/types_create_options.go index 90312e6e6..942f25629 100644 --- a/pkg/bindings/pods/types_create_options.go +++ b/pkg/bindings/pods/types_create_options.go @@ -2,12 +2,8 @@ package pods 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 *CreateOptions) 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 *CreateOptions) 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/pods/types_exists_options.go b/pkg/bindings/pods/types_exists_options.go index 0a7fbe3c9..11c6f9c05 100644 --- a/pkg/bindings/pods/types_exists_options.go +++ b/pkg/bindings/pods/types_exists_options.go @@ -2,12 +2,8 @@ package pods 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/pods/types_inspect_options.go b/pkg/bindings/pods/types_inspect_options.go index 9913eaa50..172b1303c 100644 --- a/pkg/bindings/pods/types_inspect_options.go +++ b/pkg/bindings/pods/types_inspect_options.go @@ -2,12 +2,8 @@ package pods 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 *InspectOptions) 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 *InspectOptions) 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/pods/types_kill_options.go b/pkg/bindings/pods/types_kill_options.go index dac91840c..e350746db 100644 --- a/pkg/bindings/pods/types_kill_options.go +++ b/pkg/bindings/pods/types_kill_options.go @@ -2,12 +2,8 @@ package pods 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 *KillOptions) 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 *KillOptions) 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) } // WithSignal diff --git a/pkg/bindings/pods/types_list_options.go b/pkg/bindings/pods/types_list_options.go index ab945c253..fcaeb7c1c 100644 --- a/pkg/bindings/pods/types_list_options.go +++ b/pkg/bindings/pods/types_list_options.go @@ -2,12 +2,8 @@ package pods 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) } // WithFilters diff --git a/pkg/bindings/pods/types_pause_options.go b/pkg/bindings/pods/types_pause_options.go index 177679e2a..b5aee3984 100644 --- a/pkg/bindings/pods/types_pause_options.go +++ b/pkg/bindings/pods/types_pause_options.go @@ -2,12 +2,8 @@ package pods 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 *PauseOptions) 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 *PauseOptions) 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/pods/types_prune_options.go b/pkg/bindings/pods/types_prune_options.go index 389a95579..80019a2fd 100644 --- a/pkg/bindings/pods/types_prune_options.go +++ b/pkg/bindings/pods/types_prune_options.go @@ -2,12 +2,8 @@ package pods 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 *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) } diff --git a/pkg/bindings/pods/types_remove_options.go b/pkg/bindings/pods/types_remove_options.go index dcb4106f8..e129d1e29 100644 --- a/pkg/bindings/pods/types_remove_options.go +++ b/pkg/bindings/pods/types_remove_options.go @@ -2,12 +2,8 @@ package pods 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) } // WithForce diff --git a/pkg/bindings/pods/types_restart_options.go b/pkg/bindings/pods/types_restart_options.go index 61b06f70e..7b95b91a1 100644 --- a/pkg/bindings/pods/types_restart_options.go +++ b/pkg/bindings/pods/types_restart_options.go @@ -2,12 +2,8 @@ package pods 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 *RestartOptions) 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 *RestartOptions) 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/pods/types_start_options.go b/pkg/bindings/pods/types_start_options.go index 80e3c04d5..b0d574020 100644 --- a/pkg/bindings/pods/types_start_options.go +++ b/pkg/bindings/pods/types_start_options.go @@ -2,12 +2,8 @@ package pods 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 *StartOptions) 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 *StartOptions) 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/pods/types_stats_options.go b/pkg/bindings/pods/types_stats_options.go index c8be15ee9..50a18bc6a 100644 --- a/pkg/bindings/pods/types_stats_options.go +++ b/pkg/bindings/pods/types_stats_options.go @@ -2,12 +2,8 @@ package pods 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 *StatsOptions) 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 *StatsOptions) 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/pods/types_stop_options.go b/pkg/bindings/pods/types_stop_options.go index 22b04012e..f80d391c6 100644 --- a/pkg/bindings/pods/types_stop_options.go +++ b/pkg/bindings/pods/types_stop_options.go @@ -2,12 +2,8 @@ package pods 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 *StopOptions) 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 *StopOptions) 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) } // WithTimeout diff --git a/pkg/bindings/pods/types_top_options.go b/pkg/bindings/pods/types_top_options.go index da2457809..7e05a7937 100644 --- a/pkg/bindings/pods/types_top_options.go +++ b/pkg/bindings/pods/types_top_options.go @@ -2,12 +2,8 @@ package pods 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 *TopOptions) 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 *TopOptions) 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) } // WithDescriptors diff --git a/pkg/bindings/pods/types_unpause_options.go b/pkg/bindings/pods/types_unpause_options.go index 5e2c9454b..9575e3949 100644 --- a/pkg/bindings/pods/types_unpause_options.go +++ b/pkg/bindings/pods/types_unpause_options.go @@ -2,12 +2,8 @@ package pods 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 *UnpauseOptions) 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 *UnpauseOptions) 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/secrets/types_create_options.go b/pkg/bindings/secrets/types_create_options.go index 7629b3e5d..254f91147 100644 --- a/pkg/bindings/secrets/types_create_options.go +++ b/pkg/bindings/secrets/types_create_options.go @@ -2,12 +2,8 @@ package secrets 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 *CreateOptions) 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 *CreateOptions) 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) } // WithDriver diff --git a/pkg/bindings/secrets/types_inspect_options.go b/pkg/bindings/secrets/types_inspect_options.go index 8213c73bf..0a8f8ca19 100644 --- a/pkg/bindings/secrets/types_inspect_options.go +++ b/pkg/bindings/secrets/types_inspect_options.go @@ -2,12 +2,8 @@ package secrets 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 *InspectOptions) 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 *InspectOptions) 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/secrets/types_list_options.go b/pkg/bindings/secrets/types_list_options.go index eab0f5466..e232c543b 100644 --- a/pkg/bindings/secrets/types_list_options.go +++ b/pkg/bindings/secrets/types_list_options.go @@ -2,12 +2,8 @@ package secrets 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 *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) } diff --git a/pkg/bindings/secrets/types_remove_options.go b/pkg/bindings/secrets/types_remove_options.go index 151c1d90c..43c1fb545 100644 --- a/pkg/bindings/secrets/types_remove_options.go +++ b/pkg/bindings/secrets/types_remove_options.go @@ -2,12 +2,8 @@ package secrets 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 *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) } diff --git a/pkg/bindings/system/types_disk_options.go b/pkg/bindings/system/types_disk_options.go index 77428c10c..118d2e8d2 100644 --- a/pkg/bindings/system/types_disk_options.go +++ b/pkg/bindings/system/types_disk_options.go @@ -2,12 +2,8 @@ package system 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 *DiskOptions) 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 *DiskOptions) 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/system/types_events_options.go b/pkg/bindings/system/types_events_options.go index dd7706178..f6717f38d 100644 --- a/pkg/bindings/system/types_events_options.go +++ b/pkg/bindings/system/types_events_options.go @@ -2,12 +2,8 @@ package system 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 *EventsOptions) 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 *EventsOptions) 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) } // WithFilters diff --git a/pkg/bindings/system/types_info_options.go b/pkg/bindings/system/types_info_options.go index 162ec3e88..bc6c67282 100644 --- a/pkg/bindings/system/types_info_options.go +++ b/pkg/bindings/system/types_info_options.go @@ -2,12 +2,8 @@ package system 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 *InfoOptions) 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 *InfoOptions) 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/system/types_prune_options.go b/pkg/bindings/system/types_prune_options.go index f2ae5e657..c08a9baf3 100644 --- a/pkg/bindings/system/types_prune_options.go +++ b/pkg/bindings/system/types_prune_options.go @@ -2,12 +2,8 @@ package system 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/system/types_version_options.go b/pkg/bindings/system/types_version_options.go index b6026fa8c..fa6956677 100644 --- a/pkg/bindings/system/types_version_options.go +++ b/pkg/bindings/system/types_version_options.go @@ -2,12 +2,8 @@ package system 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 *VersionOptions) 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 *VersionOptions) 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/util/util.go b/pkg/bindings/util/util.go index 403846355..6296fc22f 100644 --- a/pkg/bindings/util/util.go +++ b/pkg/bindings/util/util.go @@ -1,8 +1,13 @@ package util import ( + "errors" + "net/url" "reflect" "strconv" + "strings" + + jsoniter "github.com/json-iterator/go" ) func IsSimpleType(f reflect.Value) bool { @@ -28,3 +33,59 @@ func SimpleTypeToParam(f reflect.Value) string { } panic("the input parameter is not a simple type") } + +func Changed(o interface{}, fieldName string) bool { + r := reflect.ValueOf(o) + value := reflect.Indirect(r).FieldByName(fieldName) + return !value.IsNil() +} + +func ToParams(o interface{}) (url.Values, error) { + params := url.Values{} + if o == nil || reflect.ValueOf(o).IsNil() { + 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 !Changed(o, fieldName) { + continue + } + fieldName = strings.ToLower(fieldName) + f := s.Field(i) + if reflect.Ptr == f.Kind() { + f = f.Elem() + } + switch { + case IsSimpleType(f): + params.Set(fieldName, SimpleTypeToParam(f)) + case f.Kind() == reflect.Slice: + for i := 0; i < f.Len(); i++ { + elem := f.Index(i) + if IsSimpleType(elem) { + params.Add(fieldName, 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 +} diff --git a/pkg/bindings/volumes/types_create_options.go b/pkg/bindings/volumes/types_create_options.go index 2dcbaf611..45053e261 100644 --- a/pkg/bindings/volumes/types_create_options.go +++ b/pkg/bindings/volumes/types_create_options.go @@ -2,12 +2,8 @@ package volumes 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 *CreateOptions) 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 *CreateOptions) 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/volumes/types_exists_options.go b/pkg/bindings/volumes/types_exists_options.go index ebfabc061..044f0501d 100644 --- a/pkg/bindings/volumes/types_exists_options.go +++ b/pkg/bindings/volumes/types_exists_options.go @@ -2,12 +2,8 @@ package volumes 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/volumes/types_inspect_options.go b/pkg/bindings/volumes/types_inspect_options.go index 3176e0ef6..e6397a0d2 100644 --- a/pkg/bindings/volumes/types_inspect_options.go +++ b/pkg/bindings/volumes/types_inspect_options.go @@ -2,12 +2,8 @@ package volumes 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 *InspectOptions) 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 *InspectOptions) 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/volumes/types_list_options.go b/pkg/bindings/volumes/types_list_options.go index e7770d5ee..103515e99 100644 --- a/pkg/bindings/volumes/types_list_options.go +++ b/pkg/bindings/volumes/types_list_options.go @@ -2,12 +2,8 @@ package volumes 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) } // WithFilters diff --git a/pkg/bindings/volumes/types_prune_options.go b/pkg/bindings/volumes/types_prune_options.go index 78245f649..eb910e05d 100644 --- a/pkg/bindings/volumes/types_prune_options.go +++ b/pkg/bindings/volumes/types_prune_options.go @@ -2,12 +2,8 @@ package volumes 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) } // WithFilters diff --git a/pkg/bindings/volumes/types_remove_options.go b/pkg/bindings/volumes/types_remove_options.go index 13ac6a346..30cb923c7 100644 --- a/pkg/bindings/volumes/types_remove_options.go +++ b/pkg/bindings/volumes/types_remove_options.go @@ -2,12 +2,8 @@ package volumes 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) } // WithForce |