1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 16:06:56 +00:00
kyverno/pkg/engine/common/common.go

28 lines
574 B
Go
Raw Normal View History

package common
import (
"fmt"
"strconv"
)
2020-10-22 11:59:11 -07:00
// convertNumberToString converts value to string
func convertNumberToString(value interface{}) (string, error) {
if value == nil {
return "0", nil
}
switch typed := value.(type) {
case string:
return 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
2020-11-03 15:31:58 -08:00
case nil:
return "", fmt.Errorf("got empty string, expect %v", value)
default:
2020-10-22 11:59:11 -07:00
return "", fmt.Errorf("could not convert %v to string", typed)
}
}