From e5d61077955b77377b8fc3fe37b1d0f56fe8b2b4 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Fri, 29 Jul 2022 17:05:39 +0800 Subject: [PATCH] add test file --- pkg/tools/tools.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 pkg/tools/tools.go diff --git a/pkg/tools/tools.go b/pkg/tools/tools.go new file mode 100644 index 000000000..a3baa5f3e --- /dev/null +++ b/pkg/tools/tools.go @@ -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 +}