github.com/wangyougui/gf/v2@v2.6.5/container/gvar/gvar_vars.go (about)

     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/wangyougui/gf.
     6  
     7  package gvar
     8  
     9  import (
    10  	"github.com/wangyougui/gf/v2/util/gconv"
    11  )
    12  
    13  // Vars is a slice of *Var.
    14  type Vars []*Var
    15  
    16  // Strings converts and returns `vs` as []string.
    17  func (vs Vars) Strings() (s []string) {
    18  	for _, v := range vs {
    19  		s = append(s, v.String())
    20  	}
    21  	return s
    22  }
    23  
    24  // Interfaces converts and returns `vs` as []interface{}.
    25  func (vs Vars) Interfaces() (s []interface{}) {
    26  	for _, v := range vs {
    27  		s = append(s, v.Val())
    28  	}
    29  	return s
    30  }
    31  
    32  // Float32s converts and returns `vs` as []float32.
    33  func (vs Vars) Float32s() (s []float32) {
    34  	for _, v := range vs {
    35  		s = append(s, v.Float32())
    36  	}
    37  	return s
    38  }
    39  
    40  // Float64s converts and returns `vs` as []float64.
    41  func (vs Vars) Float64s() (s []float64) {
    42  	for _, v := range vs {
    43  		s = append(s, v.Float64())
    44  	}
    45  	return s
    46  }
    47  
    48  // Ints converts and returns `vs` as []Int.
    49  func (vs Vars) Ints() (s []int) {
    50  	for _, v := range vs {
    51  		s = append(s, v.Int())
    52  	}
    53  	return s
    54  }
    55  
    56  // Int8s converts and returns `vs` as []int8.
    57  func (vs Vars) Int8s() (s []int8) {
    58  	for _, v := range vs {
    59  		s = append(s, v.Int8())
    60  	}
    61  	return s
    62  }
    63  
    64  // Int16s converts and returns `vs` as []int16.
    65  func (vs Vars) Int16s() (s []int16) {
    66  	for _, v := range vs {
    67  		s = append(s, v.Int16())
    68  	}
    69  	return s
    70  }
    71  
    72  // Int32s converts and returns `vs` as []int32.
    73  func (vs Vars) Int32s() (s []int32) {
    74  	for _, v := range vs {
    75  		s = append(s, v.Int32())
    76  	}
    77  	return s
    78  }
    79  
    80  // Int64s converts and returns `vs` as []int64.
    81  func (vs Vars) Int64s() (s []int64) {
    82  	for _, v := range vs {
    83  		s = append(s, v.Int64())
    84  	}
    85  	return s
    86  }
    87  
    88  // Uints converts and returns `vs` as []uint.
    89  func (vs Vars) Uints() (s []uint) {
    90  	for _, v := range vs {
    91  		s = append(s, v.Uint())
    92  	}
    93  	return s
    94  }
    95  
    96  // Uint8s converts and returns `vs` as []uint8.
    97  func (vs Vars) Uint8s() (s []uint8) {
    98  	for _, v := range vs {
    99  		s = append(s, v.Uint8())
   100  	}
   101  	return s
   102  }
   103  
   104  // Uint16s converts and returns `vs` as []uint16.
   105  func (vs Vars) Uint16s() (s []uint16) {
   106  	for _, v := range vs {
   107  		s = append(s, v.Uint16())
   108  	}
   109  	return s
   110  }
   111  
   112  // Uint32s converts and returns `vs` as []uint32.
   113  func (vs Vars) Uint32s() (s []uint32) {
   114  	for _, v := range vs {
   115  		s = append(s, v.Uint32())
   116  	}
   117  	return s
   118  }
   119  
   120  // Uint64s converts and returns `vs` as []uint64.
   121  func (vs Vars) Uint64s() (s []uint64) {
   122  	for _, v := range vs {
   123  		s = append(s, v.Uint64())
   124  	}
   125  	return s
   126  }
   127  
   128  // Scan converts `vs` to []struct/[]*struct.
   129  func (vs Vars) Scan(pointer interface{}, mapping ...map[string]string) error {
   130  	return gconv.Structs(vs.Interfaces(), pointer, mapping...)
   131  }