mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-10 05:24:18 +09:00
Enable [`forcetypeassert`](https://github.com/gostaticanalysis/forcetypeassert) linter to prevent unchecked type assertions. ~650 issues fixed, most fixes were clean, some use `setting.PanicInDevOrTesting`. The only behaviour changes are where code would previously send a 500 error or panic, a 4xx error is now emitted. Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
27 lines
484 B
Go
27 lines
484 B
Go
// Copyright 2021 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package util
|
|
|
|
// PaginateSlice cut a slice as per pagination options
|
|
// if page = 0 it do not paginate
|
|
func PaginateSlice[S ~[]E, E any](list S, page, pageSize int) S {
|
|
if page <= 0 || pageSize <= 0 {
|
|
return list
|
|
}
|
|
|
|
page--
|
|
|
|
if page*pageSize >= len(list) {
|
|
return list[len(list):]
|
|
}
|
|
|
|
list = list[page*pageSize:]
|
|
|
|
if len(list) > pageSize {
|
|
return list[:pageSize]
|
|
}
|
|
|
|
return list
|
|
}
|