mirror of
https://github.com/onyx-and-iris/xair-cli.git
synced 2026-02-04 07:27:47 +00:00
34 lines
643 B
Go
34 lines
643 B
Go
package cmd
|
|
|
|
import (
|
|
"strconv"
|
|
)
|
|
|
|
// mustConvToFloat64 converts a string to float64, panicking on error.
|
|
func mustConvToFloat64(floatStr string) float64 {
|
|
level, err := strconv.ParseFloat(floatStr, 64)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return level
|
|
}
|
|
|
|
// mustConvToInt converts a string to int, panicking on error.
|
|
func mustConvToInt(intStr string) int {
|
|
val, err := strconv.Atoi(intStr)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return val
|
|
}
|
|
|
|
// generic indexOf returns the index of elem in slice, or -1 if not found.
|
|
func indexOf[T comparable](slice []T, elem T) int {
|
|
for i, v := range slice {
|
|
if v == elem {
|
|
return i
|
|
}
|
|
}
|
|
return -1
|
|
}
|