-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(controller): support float for param value (#4490)
Signed-off-by: Arghya Sadhu <arghya88@gmail.com>
- Loading branch information
Showing
21 changed files
with
592 additions
and
561 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"strconv" | ||
) | ||
|
||
// * It's JSON type is just string. | ||
// * It will unmarshall int64, int32, float64, float32, boolean, a plain string and represents it as string. | ||
// * It will marshall back to string - marshalling is not symmetric. | ||
type AnyString string | ||
|
||
func ParseAnyString(val interface{}) AnyString { | ||
return AnyString(fmt.Sprintf("%v", val)) | ||
} | ||
|
||
func AnyStringPtr(val interface{}) *AnyString { | ||
i := ParseAnyString(val) | ||
return &i | ||
} | ||
|
||
func (i *AnyString) UnmarshalJSON(value []byte) error { | ||
var v interface{} | ||
err := json.Unmarshal(value, &v) | ||
if err != nil { | ||
return err | ||
} | ||
switch v := v.(type) { | ||
case float64: | ||
*i = AnyString(strconv.FormatFloat(v, 'f', -1, 64)) | ||
case float32: | ||
*i = AnyString(strconv.FormatFloat(float64(v), 'f', -1, 32)) | ||
case int64: | ||
*i = AnyString(strconv.FormatInt(v, 10)) | ||
case int32: | ||
*i = AnyString(strconv.FormatInt(int64(v), 10)) | ||
case bool: | ||
*i = AnyString(strconv.FormatBool(v)) | ||
case string: | ||
*i = AnyString(v) | ||
} | ||
return nil | ||
} | ||
|
||
func (i AnyString) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(string(i)) | ||
} | ||
|
||
func (i AnyString) String() string { | ||
return string(i) | ||
} |
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
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
Oops, something went wrong.