convert.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package help
  2. type intConverter func(interface{}) int64
  3. func getIntConverter(data interface{}) intConverter {
  4. switch data.(type) {
  5. case int:
  6. return func(i interface{}) int64 {
  7. return int64(i.(int))
  8. }
  9. case int8:
  10. return func(i interface{}) int64 {
  11. return int64(i.(int8))
  12. }
  13. case int16:
  14. return func(i interface{}) int64 {
  15. return int64(i.(int16))
  16. }
  17. case int32:
  18. return func(i interface{}) int64 {
  19. return int64(i.(int32))
  20. }
  21. }
  22. return func(i interface{}) int64 {
  23. return i.(int64)
  24. }
  25. }
  26. type uintConverter func(interface{}) uint64
  27. func getUIntConverter(data interface{}) uintConverter {
  28. switch data.(type) {
  29. case uint:
  30. return func(i interface{}) uint64 {
  31. return uint64(i.(uint))
  32. }
  33. case uint8:
  34. return func(i interface{}) uint64 {
  35. return uint64(i.(uint8))
  36. }
  37. case uint16:
  38. return func(i interface{}) uint64 {
  39. return uint64(i.(uint16))
  40. }
  41. case uint32:
  42. return func(i interface{}) uint64 {
  43. return uint64(i.(uint32))
  44. }
  45. }
  46. return func(i interface{}) uint64 {
  47. return i.(uint64)
  48. }
  49. }
  50. type floatConverter func(interface{}) float64
  51. func getFloatConverter(data interface{}) floatConverter {
  52. switch data.(type) {
  53. case float32:
  54. return func(i interface{}) float64 {
  55. return float64(i.(float32))
  56. }
  57. }
  58. return func(i interface{}) float64 {
  59. return i.(float64)
  60. }
  61. }