Documentation ¶
Index ¶
- Constants
- Variables
- func AlignTfMSecs(timeMSecs int64, tfMSecs int64) int64
- func AlignTfMSecsOffset(timeMSecs, tfMSecs, offset int64) int64
- func AlignTfSecs(timeSecs int64, tfSecs int) int64
- func AlignTfSecsOffset(timeSecs int64, tfSecs int, offset int) int64
- func ArrContains[T comparable](s []T, e T) bool
- func ArrSum(s []float64) float64
- func ByteToStruct[T any](byteChan <-chan []byte, outChan chan<- T, numType int)
- func DecToPrec(num string, countMode int, precision string, isRound, padZero bool) (string, error)
- func Eddsa(request []byte, secret []byte) (string, error)
- func EncodeToLatin1(input string) ([]byte, error)
- func EncodeURIComponent(str string, safe string) string
- func EqualIn(a, b, thres float64) bool
- func EqualNearly(a, b float64) bool
- func GetMapFloat(data map[string]interface{}, key string) float64
- func GetMapVal[T any](items map[string]interface{}, key string, defVal T) T
- func GetTfAlignOrigin(secs int) (string, int)
- func HMAC(request []byte, secret []byte, algorithm func() hash.Hash, digest string) string
- func ISO8601(millis int64) string
- func IsNil(i interface{}) bool
- func KeysOfMap[M ~map[K]V, K comparable, V any](m M) []K
- func MD5(data []byte) string
- func MapValStr(input map[string]interface{}) map[string]string
- func Marshal(v any) ([]byte, error)
- func MarshalString(v any) (string, error)
- func OmitMapKeys(items map[string]interface{}, keys ...string)
- func ParseJsonNumber(data interface{}) error
- func ParseTimeFrame(timeframe string) (int, *errs.Error)
- func ParseTimeRanges(items []string, loc *time.Location) ([][2]int64, *errs.Error)
- func PopMapVal[T any](items map[string]interface{}, key string, defVal T) T
- func PrecFloat64(num float64, prec float64, isRound bool, mode int) (float64, error)
- func PrecFloat64Str(num float64, prec float64, isRound bool, mode int) (string, error)
- func PrecisionFromString(input string) float64
- func ReadCacheFile(key string) (string, *errs.Error)
- func ReadFile(path string) ([]byte, error)
- func ReadJsonFile(path string, obj interface{}, numType int) error
- func RegTfSecs(items map[string]int)
- func SafeMapVal[T any](items map[string]string, key string, defVal T) (result T, err error)
- func SafeParams(params map[string]interface{}) map[string]interface{}
- func SecsToTF(tfSecs int) string
- func SetFieldBy[T any](field *T, items map[string]interface{}, key string, defVal T)
- func Signature(data string, secret string, method string, hashName string, digest string) (string, *errs.Error)
- func SnakeToCamel(input string) string
- func TFToSecs(timeFrame string) int
- func UUID(length int) string
- func Unmarshal(data []byte, out interface{}, numType int) error
- func UnmarshalString(text string, out interface{}, numType int) error
- func UrlEncodeMap(params map[string]interface{}, escape bool) string
- func ValsOfMap[M ~map[K]V, K comparable, V any](m M) []V
- func WriteCacheFile(key, content string, expSecs int) *errs.Error
- func WriteFile(path string, data []byte) error
- func WriteJsonFile(path string, data interface{}) error
- func YMD(timestamp int64, separator string, fullYear bool) string
- type StrType
- type TFOrigin
Constants ¶
const ( StrStr = 0 StrInt = 1 StrFloat = 2 )
const ( PrecModeDecimalPlace = 2 // 保留小数点后指定位 PrecModeSignifDigits = 3 // 保留全部有效数字个数 PrecModeTickSize = 4 // 返回给定的数字的整数倍 )
const ( JsonNumDefault = 0 // equal to JsonNumFloat JsonNumFloat = 0 // parse number in json to float64 JsonNumStr = 1 // keep number in json as json.Number type JsonNumAuto = 2 // auto parse json.Number to int64/float64 in []interface{} map[string]interface{} )
const ( SecsMin = 60 SecsHour = SecsMin * 60 SecsDay = SecsHour * 24 SecsWeek = SecsDay * 7 SecsMon = SecsDay * 30 SecsQtr = SecsMon * 3 SecsYear = SecsDay * 365 )
const (
UriEncodeSafe = "~()*!.'"
)
Variables ¶
var ( ErrInvalidPrecision = errors.New("invalid precision") ErrNegPrecForTickSize = errors.New("negative precision for tick size") )
Functions ¶
func AlignTfMSecs ¶ added in v0.2.6
AlignTfMSecs Convert the given 13 millisecond timestamp to the header start timestamp for the specified time period 将给定的13位毫秒级时间戳,转为指定时间周期下,的头部开始时间戳
func AlignTfMSecsOffset ¶ added in v0.2.6
func AlignTfSecs ¶ added in v0.2.6
AlignTfSecs Convert the given 10 second timestamp to the header start timestamp for the specified time period 将给定的10位秒级时间戳,转为指定时间周期下,的头部开始时间戳
func AlignTfSecsOffset ¶ added in v0.2.6
AlignTfSecsOffset Convert the given 10 second timestamp to the header start timestamp for the specified time period, using the specified offset 将给定的10位秒级时间戳,转为指定时间周期下,的头部开始时间戳,使用指定偏移
func ArrContains ¶
func ArrContains[T comparable](s []T, e T) bool
func ByteToStruct ¶
ByteToStruct 将[]byte类型的chan通道,转为指定类型通道
func DecToPrec ¶
DecToPrec 将数字转换为指定精度返回
num: 需要处理的数字字符串 countMode: PrecModeDecimalPlace 保留小数点后指定位; PrecModeSignifDigits 保留全部有效数字个数 PrecModeTickSize 返回给定的数字的整数倍 precision: 结合countMode使用,正整数,负整数,正浮点数 isRound: 是否四舍五入,默认截断 padZero: 是否尾部填充0到指定长度
func EncodeToLatin1 ¶
func EncodeURIComponent ¶
func GetMapFloat ¶
func GetTfAlignOrigin ¶ added in v0.2.6
func IsNil ¶
func IsNil(i interface{}) bool
IsNil 判断是否为nil
golang中类型和值是分开存储的,如果一个指针有类型,值为nil,直接判断==nil会返回false
func KeysOfMap ¶ added in v0.2.3
func KeysOfMap[M ~map[K]V, K comparable, V any](m M) []K
func MarshalString ¶ added in v0.2.9
func OmitMapKeys ¶
func ParseJsonNumber ¶ added in v0.2.10
func ParseJsonNumber(data interface{}) error
ParseJsonNumber
parse json.Number to int64/float64 in *[]interface{} *map[string]interface{}
func ParseTimeRanges ¶ added in v0.2.1
func PrecFloat64 ¶
PrecFloat64 对给定浮点数取近似值,精确到指定位数
func PrecFloat64Str ¶
func PrecisionFromString ¶
PrecisionFromString 1e-4 -> 4 0.000001 -> 6 100 -> 0
func SafeMapVal ¶
SafeMapVal 从字典中读取给定键的值,并自动转换为需要的类型,如果出错则返回默认值
func SafeParams ¶
func SecsToTF ¶ added in v0.2.6
SecsToTF Convert the seconds of a time period into a time period 将时间周期的秒数,转为时间周期
func SetFieldBy ¶
func Signature ¶
func Signature(data string, secret string, method string, hashName string, digest string) (string, *errs.Error)
Signature method: rsa, eddsa, hmac
hashName: rsa: sha256/sha384/sha512 eddsa: 不需要 hmac:sha256/sha384/sha512 digest: hmac: base64/hex
func SnakeToCamel ¶ added in v0.2.4
func TFToSecs ¶ added in v0.2.6
TFToSecs Convert the time cycle to seconds Supporting units: s, m, h, d, M, Q, Y 将时间周期转为秒 支持单位:s, m, h, d, M, Q, Y
func Unmarshal ¶ added in v0.2.0
Unmarshal decode json
numType: JsonNumDefault(JsonNumFloat), JsonNumStr, JsonNumAuto
func UnmarshalString ¶ added in v0.2.0
UnmarshalString decode json (big int as float64)
numType: JsonNumDefault(JsonNumFloat), JsonNumStr, JsonNumAuto
func UrlEncodeMap ¶
UrlEncodeMap 将map编码为url查询字符串 escape: 是否对键和值进行编码
func ValsOfMap ¶ added in v0.2.3
func ValsOfMap[M ~map[K]V, K comparable, V any](m M) []V