main.go 548 B

123456789101112131415161718192021222324
  1. package main
  2. import "github.com/spf13/cast"
  3. func main() {
  4. cast.ToString("mayonegg") // "mayonegg"
  5. cast.ToString(8) // "8"
  6. cast.ToString(8.31) // "8.31"
  7. cast.ToString([]byte("one time")) // "one time"
  8. cast.ToString(nil) // ""
  9. var foo any = "one more time"
  10. cast.ToString(foo) // "one more time"
  11. cast.ToInt(8) // 8
  12. cast.ToInt(8.31) // 8
  13. cast.ToInt("8") // 8
  14. cast.ToInt(true) // 1
  15. cast.ToInt(false) // 0
  16. var eight any = 8
  17. cast.ToInt(eight) // 8
  18. cast.ToInt(nil) // 0
  19. }