diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-02-03 04:59:23 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-03 04:59:23 -0500 |
commit | 881f3d788d48b683e674d1f9778d581370c9c11e (patch) | |
tree | a05094ec7a8ebee7007b734b1bd73b13ba42c1f6 /pkg/bindings/util/util.go | |
parent | d1e0afdd47c1868ce0d22e48ae9b0b9d89ba6274 (diff) | |
parent | bde23a0219729e530895153b12d5578e9f02dab8 (diff) | |
download | podman-881f3d788d48b683e674d1f9778d581370c9c11e.tar.gz podman-881f3d788d48b683e674d1f9778d581370c9c11e.tar.bz2 podman-881f3d788d48b683e674d1f9778d581370c9c11e.zip |
Merge pull request #9203 from matejvasek/improve_param_serder_generator
[NO TESTS NEEDED] Improve binding generator
Diffstat (limited to 'pkg/bindings/util/util.go')
-rw-r--r-- | pkg/bindings/util/util.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/pkg/bindings/util/util.go b/pkg/bindings/util/util.go new file mode 100644 index 000000000..403846355 --- /dev/null +++ b/pkg/bindings/util/util.go @@ -0,0 +1,30 @@ +package util + +import ( + "reflect" + "strconv" +) + +func IsSimpleType(f reflect.Value) bool { + switch f.Kind() { + case reflect.Bool, reflect.Int, reflect.Int64, reflect.Uint, reflect.Uint64, reflect.String: + return true + } + return false +} + +func SimpleTypeToParam(f reflect.Value) string { + switch f.Kind() { + case reflect.Bool: + return strconv.FormatBool(f.Bool()) + case reflect.Int, reflect.Int64: + // f.Int() is always an int64 + return strconv.FormatInt(f.Int(), 10) + case reflect.Uint, reflect.Uint64: + // f.Uint() is always an uint64 + return strconv.FormatUint(f.Uint(), 10) + case reflect.String: + return f.String() + } + panic("the input parameter is not a simple type") +} |