mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-04 12:52:27 +08:00
* * 公众号菜单管理,set相关函数,返回btn本身,方便以字面量的方式创建多个菜单,更直观,方便管理 * * golangci-lint fix * * 获取二维码ticket接口没有往上抛接口错误 * * 增加GetOpenID方法,以获取消息的生产用户openID * * 支持公众号账号迁移,获取openID变化接口 * * bugfix * * golint fix * * golint fix
42 lines
750 B
Go
42 lines
750 B
Go
package util
|
|
|
|
//SliceChunk 用于将字符串切片分块
|
|
func SliceChunk(src []string, chunkSize int) (chunks [][]string) {
|
|
total := len(src)
|
|
chunks = make([][]string, 0)
|
|
if chunkSize < 1 {
|
|
chunkSize = 1
|
|
}
|
|
if total == 0 {
|
|
return
|
|
}
|
|
|
|
chunkNum := total / chunkSize
|
|
if total%chunkSize != 0 {
|
|
chunkNum++
|
|
}
|
|
|
|
chunks = make([][]string, chunkNum)
|
|
|
|
for i := 0; i < chunkNum; i++ {
|
|
for j := 0; j < chunkSize; j++ {
|
|
offset := i*chunkSize + j
|
|
if offset >= total {
|
|
return
|
|
}
|
|
|
|
if chunks[i] == nil {
|
|
actualChunkSize := chunkSize
|
|
if i == chunkNum-1 && total%chunkSize != 0 {
|
|
actualChunkSize = total % chunkSize
|
|
}
|
|
chunks[i] = make([]string, actualChunkSize)
|
|
}
|
|
|
|
chunks[i][j] = src[offset]
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|