gvar_slice.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
  2. //
  3. // This Source Code Form is subject to the terms of the MIT License.
  4. // If a copy of the MIT was not distributed with this file,
  5. // You can obtain one at https://github.com/gogf/gf.
  6. package gvar
  7. import "github.com/gogf/gf/util/gconv"
  8. // Ints converts and returns `v` as []int.
  9. func (v *Var) Ints() []int {
  10. return gconv.Ints(v.Val())
  11. }
  12. // Int64s converts and returns `v` as []int64.
  13. func (v *Var) Int64s() []int64 {
  14. return gconv.Int64s(v.Val())
  15. }
  16. // Uints converts and returns `v` as []uint.
  17. func (v *Var) Uints() []uint {
  18. return gconv.Uints(v.Val())
  19. }
  20. // Uint64s converts and returns `v` as []uint64.
  21. func (v *Var) Uint64s() []uint64 {
  22. return gconv.Uint64s(v.Val())
  23. }
  24. // Floats is alias of Float64s.
  25. func (v *Var) Floats() []float64 {
  26. return gconv.Floats(v.Val())
  27. }
  28. // Float32s converts and returns `v` as []float32.
  29. func (v *Var) Float32s() []float32 {
  30. return gconv.Float32s(v.Val())
  31. }
  32. // Float64s converts and returns `v` as []float64.
  33. func (v *Var) Float64s() []float64 {
  34. return gconv.Float64s(v.Val())
  35. }
  36. // Strings converts and returns `v` as []string.
  37. func (v *Var) Strings() []string {
  38. return gconv.Strings(v.Val())
  39. }
  40. // Interfaces converts and returns `v` as []interfaces{}.
  41. func (v *Var) Interfaces() []interface{} {
  42. return gconv.Interfaces(v.Val())
  43. }
  44. // Slice is alias of Interfaces.
  45. func (v *Var) Slice() []interface{} {
  46. return v.Interfaces()
  47. }
  48. // Array is alias of Interfaces.
  49. func (v *Var) Array() []interface{} {
  50. return v.Interfaces()
  51. }
  52. // Vars converts and returns `v` as []Var.
  53. func (v *Var) Vars() []*Var {
  54. array := gconv.Interfaces(v.Val())
  55. if len(array) == 0 {
  56. return nil
  57. }
  58. vars := make([]*Var, len(array))
  59. for k, v := range array {
  60. vars[k] = New(v)
  61. }
  62. return vars
  63. }