source_util.go 352 B

123456789101112131415161718192021
  1. package extensions
  2. import (
  3. "fmt"
  4. "strconv"
  5. )
  6. func CastToString(v interface{}) (result string, ok bool) {
  7. switch v := v.(type) {
  8. case int:
  9. return strconv.Itoa(v), true
  10. case string:
  11. return v, true
  12. case bool:
  13. return strconv.FormatBool(v), true
  14. case float64, float32:
  15. return fmt.Sprintf("%.2f", v), true
  16. default:
  17. return "", false
  18. }
  19. }