mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 04:30:05 +00:00
add a helper function (#443)
This commit is contained in:
@@ -5,8 +5,11 @@ import (
|
||||
"math/big"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/exp/constraints"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
@@ -104,3 +107,14 @@ func IfOrFn[T any](a bool, x, y func() T) T {
|
||||
}
|
||||
return y()
|
||||
}
|
||||
|
||||
func Itoa[T constraints.Integer](i T) string {
|
||||
switch any(i).(type) {
|
||||
case int, int8, int16, int32, int64:
|
||||
return strconv.FormatInt(int64(i), 10)
|
||||
case uint, uint8, uint16, uint32, uint64:
|
||||
return strconv.FormatUint(uint64(i), 10)
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user