mirror of
https://github.com/HexCardGames/HexDeck.git
synced 2025-09-05 19:18:39 +02:00
39 lines
644 B
Go
39 lines
644 B
Go
package utils
|
|
|
|
import (
|
|
"os"
|
|
|
|
"golang.org/x/exp/rand"
|
|
)
|
|
|
|
func Getenv(key string, fallback string) string {
|
|
value, exists := os.LookupEnv(key)
|
|
if exists {
|
|
return value
|
|
} else {
|
|
return fallback
|
|
}
|
|
}
|
|
|
|
func RemoveSliceElement[T comparable](slice *([]T), target T) bool {
|
|
for i, el := range *slice {
|
|
if el == target {
|
|
*slice = append((*slice)[:i], (*slice)[i+1:]...)
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func ShuffleSlice[T any](slice *([]T)) {
|
|
length := len(*slice)
|
|
for i := 0; i < length; i++ {
|
|
j := rand.Intn(i + 1)
|
|
(*slice)[i], (*slice)[j] = (*slice)[j], (*slice)[i]
|
|
}
|
|
}
|
|
|
|
func Mod(a, b int) int {
|
|
return (a%b + b) % b
|
|
}
|