nuclei/pkg/utils/index.go
Tarun Koyalwar dc44105baf
nuclei v3 : misc updates (#4247)
* use parsed options while signing

* update project layout to v3

* fix .gitignore

* remove example template

* misc updates

* bump tlsx version

* hide template sig warning with env

* js: retain value while using log

* fix nil pointer derefernce

* misc doc update

---------

Co-authored-by: sandeep <8293321+ehsandeep@users.noreply.github.com>
2023-10-17 17:44:13 +05:30

17 lines
389 B
Go

package utils
// TransformIndex transforms user given index (start from 1) to array index (start from 0)
// in safe way without panic i.e negative index or index out of range
func TransformIndex[T any](arr []T, index int) int {
if index <= 1 {
// negative index
return 0
}
if index >= len(arr) {
// index out of range
return len(arr) - 1
}
// valid index
return index - 1
}