mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-09 17:37:12 +00:00
* refactor: move common utils Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com> * refactor: make response type (RuleType) typed Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com> * fix: merge Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com> Co-authored-by: shuting <shuting@nirmata.com> Co-authored-by: Vyankatesh Kudtarkar <vyankateshkd@gmail.com>
27 lines
582 B
Go
27 lines
582 B
Go
package common
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
)
|
|
|
|
// convertNumberToString converts value to string
|
|
func convertNumberToString(value interface{}) (string, error) {
|
|
if value == nil {
|
|
return "0", nil
|
|
}
|
|
switch typed := value.(type) {
|
|
case string:
|
|
return string(typed), nil
|
|
case float64:
|
|
return fmt.Sprintf("%f", typed), nil
|
|
case int64:
|
|
return strconv.FormatInt(typed, 10), nil
|
|
case int:
|
|
return strconv.Itoa(typed), nil
|
|
case nil:
|
|
return "", fmt.Errorf("got empty string, expect %v", value)
|
|
default:
|
|
return "", fmt.Errorf("could not convert %v to string", typed)
|
|
}
|
|
}
|