-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add binding options for container|pod exists
It turns out an options was added to container exists so it makes sense to have pods and container exists calls have an optional structure for options. Signed-off-by: baude <[email protected]>
- Loading branch information
Showing
15 changed files
with
326 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package containers | ||
|
||
import ( | ||
"net/url" | ||
"reflect" | ||
"strconv" | ||
"strings" | ||
|
||
jsoniter "github.com/json-iterator/go" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
/* | ||
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() | ||
} | ||
|
||
// 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 f.Kind() { | ||
case reflect.Bool: | ||
params.Set(fieldName, strconv.FormatBool(f.Bool())) | ||
case reflect.String: | ||
params.Set(fieldName, f.String()) | ||
case reflect.Int, reflect.Int64: | ||
// f.Int() is always an int64 | ||
params.Set(fieldName, strconv.FormatInt(f.Int(), 10)) | ||
case reflect.Uint, reflect.Uint64: | ||
// f.Uint() is always an uint64 | ||
params.Set(fieldName, strconv.FormatUint(f.Uint(), 10)) | ||
case reflect.Slice: | ||
typ := reflect.TypeOf(f.Interface()).Elem() | ||
switch typ.Kind() { | ||
case reflect.String: | ||
sl := f.Slice(0, f.Len()) | ||
s, ok := sl.Interface().([]string) | ||
if !ok { | ||
return nil, errors.New("failed to convert to string slice") | ||
} | ||
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 | ||
} | ||
|
||
// WithExternal | ||
func (o *ExistsOptions) WithExternal(value bool) *ExistsOptions { | ||
v := &value | ||
o.External = v | ||
return o | ||
} | ||
|
||
// GetExternal | ||
func (o *ExistsOptions) GetExternal() bool { | ||
var external bool | ||
if o.External == nil { | ||
return external | ||
} | ||
return *o.External | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package images | ||
|
||
import ( | ||
"net/url" | ||
"reflect" | ||
"strconv" | ||
"strings" | ||
|
||
jsoniter "github.com/json-iterator/go" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
/* | ||
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() | ||
} | ||
|
||
// 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 f.Kind() { | ||
case reflect.Bool: | ||
params.Set(fieldName, strconv.FormatBool(f.Bool())) | ||
case reflect.String: | ||
params.Set(fieldName, f.String()) | ||
case reflect.Int, reflect.Int64: | ||
// f.Int() is always an int64 | ||
params.Set(fieldName, strconv.FormatInt(f.Int(), 10)) | ||
case reflect.Uint, reflect.Uint64: | ||
// f.Uint() is always an uint64 | ||
params.Set(fieldName, strconv.FormatUint(f.Uint(), 10)) | ||
case reflect.Slice: | ||
typ := reflect.TypeOf(f.Interface()).Elem() | ||
switch typ.Kind() { | ||
case reflect.String: | ||
sl := f.Slice(0, f.Len()) | ||
s, ok := sl.Interface().([]string) | ||
if !ok { | ||
return nil, errors.New("failed to convert to string slice") | ||
} | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package pods | ||
|
||
import ( | ||
"net/url" | ||
"reflect" | ||
"strconv" | ||
"strings" | ||
|
||
jsoniter "github.com/json-iterator/go" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
/* | ||
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() | ||
} | ||
|
||
// 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 f.Kind() { | ||
case reflect.Bool: | ||
params.Set(fieldName, strconv.FormatBool(f.Bool())) | ||
case reflect.String: | ||
params.Set(fieldName, f.String()) | ||
case reflect.Int, reflect.Int64: | ||
// f.Int() is always an int64 | ||
params.Set(fieldName, strconv.FormatInt(f.Int(), 10)) | ||
case reflect.Uint, reflect.Uint64: | ||
// f.Uint() is always an uint64 | ||
params.Set(fieldName, strconv.FormatUint(f.Uint(), 10)) | ||
case reflect.Slice: | ||
typ := reflect.TypeOf(f.Interface()).Elem() | ||
switch typ.Kind() { | ||
case reflect.String: | ||
sl := f.Slice(0, f.Len()) | ||
s, ok := sl.Interface().([]string) | ||
if !ok { | ||
return nil, errors.New("failed to convert to string slice") | ||
} | ||
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 | ||
} |
Oops, something went wrong.