|
| 1 | +package containers |
| 2 | + |
| 3 | +import ( |
| 4 | + "net/url" |
| 5 | + "reflect" |
| 6 | + "strconv" |
| 7 | + "strings" |
| 8 | + |
| 9 | + jsoniter "github.com/json-iterator/go" |
| 10 | + "github.com/pkg/errors" |
| 11 | +) |
| 12 | + |
| 13 | +/* |
| 14 | +This file is generated automatically by go generate. Do not edit. |
| 15 | +*/ |
| 16 | + |
| 17 | +// Changed |
| 18 | +func (o *RenameOptions) Changed(fieldName string) bool { |
| 19 | + r := reflect.ValueOf(o) |
| 20 | + value := reflect.Indirect(r).FieldByName(fieldName) |
| 21 | + return !value.IsNil() |
| 22 | +} |
| 23 | + |
| 24 | +// ToParams |
| 25 | +func (o *RenameOptions) ToParams() (url.Values, error) { |
| 26 | + params := url.Values{} |
| 27 | + if o == nil { |
| 28 | + return params, nil |
| 29 | + } |
| 30 | + json := jsoniter.ConfigCompatibleWithStandardLibrary |
| 31 | + s := reflect.ValueOf(o) |
| 32 | + if reflect.Ptr == s.Kind() { |
| 33 | + s = s.Elem() |
| 34 | + } |
| 35 | + sType := s.Type() |
| 36 | + for i := 0; i < s.NumField(); i++ { |
| 37 | + fieldName := sType.Field(i).Name |
| 38 | + if !o.Changed(fieldName) { |
| 39 | + continue |
| 40 | + } |
| 41 | + fieldName = strings.ToLower(fieldName) |
| 42 | + f := s.Field(i) |
| 43 | + if reflect.Ptr == f.Kind() { |
| 44 | + f = f.Elem() |
| 45 | + } |
| 46 | + switch f.Kind() { |
| 47 | + case reflect.Bool: |
| 48 | + params.Set(fieldName, strconv.FormatBool(f.Bool())) |
| 49 | + case reflect.String: |
| 50 | + params.Set(fieldName, f.String()) |
| 51 | + case reflect.Int, reflect.Int64: |
| 52 | + // f.Int() is always an int64 |
| 53 | + params.Set(fieldName, strconv.FormatInt(f.Int(), 10)) |
| 54 | + case reflect.Uint, reflect.Uint64: |
| 55 | + // f.Uint() is always an uint64 |
| 56 | + params.Set(fieldName, strconv.FormatUint(f.Uint(), 10)) |
| 57 | + case reflect.Slice: |
| 58 | + typ := reflect.TypeOf(f.Interface()).Elem() |
| 59 | + switch typ.Kind() { |
| 60 | + case reflect.String: |
| 61 | + sl := f.Slice(0, f.Len()) |
| 62 | + s, ok := sl.Interface().([]string) |
| 63 | + if !ok { |
| 64 | + return nil, errors.New("failed to convert to string slice") |
| 65 | + } |
| 66 | + for _, val := range s { |
| 67 | + params.Add(fieldName, val) |
| 68 | + } |
| 69 | + default: |
| 70 | + return nil, errors.Errorf("unknown slice type %s", f.Kind().String()) |
| 71 | + } |
| 72 | + case reflect.Map: |
| 73 | + lowerCaseKeys := make(map[string][]string) |
| 74 | + iter := f.MapRange() |
| 75 | + for iter.Next() { |
| 76 | + lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string) |
| 77 | + |
| 78 | + } |
| 79 | + s, err := json.MarshalToString(lowerCaseKeys) |
| 80 | + if err != nil { |
| 81 | + return nil, err |
| 82 | + } |
| 83 | + |
| 84 | + params.Set(fieldName, s) |
| 85 | + } |
| 86 | + } |
| 87 | + return params, nil |
| 88 | +} |
| 89 | + |
| 90 | +// WithName |
| 91 | +func (o *RenameOptions) WithName(value string) *RenameOptions { |
| 92 | + v := &value |
| 93 | + o.Name = v |
| 94 | + return o |
| 95 | +} |
| 96 | + |
| 97 | +// GetName |
| 98 | +func (o *RenameOptions) GetName() string { |
| 99 | + var name string |
| 100 | + if o.Name == nil { |
| 101 | + return name |
| 102 | + } |
| 103 | + return *o.Name |
| 104 | +} |
0 commit comments