mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Cloud migrations: create snapshot and store it on disk * fix merge conflicts * implement StartSnapshot for gms client * pass snapshot directory as argument to snapshot builder * ensure snapshot folder is set * make swagger-gen * remove Test_ExecuteAsyncWorkflow * pass signed in user to buildSnapshot method / use github.com/grafana/grafana-cloud-migration-snapshot to create snapshot files * fix FakeServiceImpl.CreateSnapshot * remove new line
34 lines
631 B
Go
34 lines
631 B
Go
package slicesext
|
|
|
|
import "math"
|
|
|
|
// Partitions the input into slices where the length is <= chunkSize.
|
|
//
|
|
// Example:
|
|
//
|
|
// Chunks(2, []int{1, 2, 3, 4})
|
|
// => [][]int{{1, 2}, {3, 4}}
|
|
func Chunks[T any](chunkSize int, xs []T) [][]T {
|
|
if chunkSize < 0 {
|
|
panic("chunk size must be greater than or equal to 0")
|
|
}
|
|
if chunkSize == 0 {
|
|
return [][]T{}
|
|
}
|
|
|
|
out := make([][]T, 0, int(math.Ceil(float64(len(xs))/float64(chunkSize))))
|
|
|
|
for i := 0; i < len(xs); i += chunkSize {
|
|
var chunk []T
|
|
if i+chunkSize < len(xs) {
|
|
chunk = xs[i : i+chunkSize]
|
|
} else {
|
|
chunk = xs[i:]
|
|
}
|
|
|
|
out = append(out, chunk)
|
|
}
|
|
|
|
return out
|
|
}
|