mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
add test file
This commit is contained in:
parent
490c94fa95
commit
b753536437
28
pkg/tools/tools.go
Normal file
28
pkg/tools/tools.go
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package tools
|
||||||
|
|
||||||
|
type SplitResult struct {
|
||||||
|
Item []string
|
||||||
|
}
|
||||||
|
type Splitter struct {
|
||||||
|
splitCount int
|
||||||
|
data []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSplitter(splitCount int, data []string) *Splitter {
|
||||||
|
return &Splitter{splitCount: splitCount, data: data}
|
||||||
|
}
|
||||||
|
func (s *Splitter) GetSplitResult() (result []*SplitResult) {
|
||||||
|
remain := len(s.data) % s.splitCount
|
||||||
|
integer := len(s.data) / s.splitCount
|
||||||
|
for i := 0; i < integer; i++ {
|
||||||
|
r := new(SplitResult)
|
||||||
|
r.Item = s.data[i*s.splitCount : (i+1)*s.splitCount]
|
||||||
|
result = append(result, r)
|
||||||
|
}
|
||||||
|
if remain > 0 {
|
||||||
|
r := new(SplitResult)
|
||||||
|
r.Item = s.data[integer*s.splitCount:]
|
||||||
|
result = append(result, r)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user