diff options
author | baude <bbaude@redhat.com> | 2020-12-16 15:37:43 -0600 |
---|---|---|
committer | baude <bbaude@redhat.com> | 2020-12-17 12:08:22 -0600 |
commit | 9ec7603e1bb21dab11460eb6e51578a0e29e4c66 (patch) | |
tree | 5020a88efffc411bc6b92b44eb569c6061a4dfe3 /pkg/bindings/pods/types_pause_options.go | |
parent | a17afa931d1aa73b8657cf26de3b49841837f66d (diff) | |
download | podman-9ec7603e1bb21dab11460eb6e51578a0e29e4c66.tar.gz podman-9ec7603e1bb21dab11460eb6e51578a0e29e4c66.tar.bz2 podman-9ec7603e1bb21dab11460eb6e51578a0e29e4c66.zip |
podman v3 pod bindings
add options to each pod binding for future wiggle room
Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/bindings/pods/types_pause_options.go')
-rw-r--r-- | pkg/bindings/pods/types_pause_options.go | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/pkg/bindings/pods/types_pause_options.go b/pkg/bindings/pods/types_pause_options.go new file mode 100644 index 000000000..1ba32f1a1 --- /dev/null +++ b/pkg/bindings/pods/types_pause_options.go @@ -0,0 +1,88 @@ +package pods + +import ( + "net/url" + "reflect" + "strconv" + + jsoniter "github.com/json-iterator/go" + "github.com/pkg/errors" +) + +/* +This file is generated automatically by go generate. Do not edit. + +Created 2020-12-17 07:45:33.042658764 -0600 CST m=+0.000177336 +*/ + +// Changed +func (o *PauseOptions) Changed(fieldName string) bool { + r := reflect.ValueOf(o) + value := reflect.Indirect(r).FieldByName(fieldName) + return !value.IsNil() +} + +// 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 + } + f := s.Field(i) + if reflect.Ptr == f.Kind() { + f = f.Elem() + } + switch f.Kind() { + case reflect.Bool: + params.Set(fieldName, strconv.FormatBool(f.Bool())) + case reflect.String: + params.Set(fieldName, f.String()) + case reflect.Int, reflect.Int64: + // f.Int() is always an int64 + params.Set(fieldName, strconv.FormatInt(f.Int(), 10)) + case reflect.Uint, reflect.Uint64: + // f.Uint() is always an uint64 + params.Set(fieldName, strconv.FormatUint(f.Uint(), 10)) + case reflect.Slice: + typ := reflect.TypeOf(f.Interface()).Elem() + slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap()) + switch typ.Kind() { + case reflect.String: + s, ok := slice.Interface().([]string) + if !ok { + return nil, errors.New("failed to convert to string slice") + } + for _, val := range s { + params.Add(fieldName, val) + } + default: + return nil, errors.Errorf("unknown slice type %s", f.Kind().String()) + } + case 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 +} |