26 lines
732 B
Go
26 lines
732 B
Go
// Package util provide some utility functions
|
|
package util
|
|
|
|
import (
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
// GenNanoTsStr define func to generate nanosecond timestamp string by current time
|
|
func GenNanoTsStr() string {
|
|
now := time.Now()
|
|
nanoseconds := now.UnixNano()
|
|
timestampStr := strconv.FormatInt(nanoseconds, 10)
|
|
return timestampStr
|
|
}
|
|
|
|
// Numeric define interface to constraints supporting integer and floating-point types
|
|
type Numeric interface {
|
|
int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | float32 | float64
|
|
}
|
|
|
|
// SecondsToDuration define func to convert Numeric type param to time duration
|
|
func SecondsToDuration[T Numeric](seconds T) time.Duration {
|
|
return time.Duration(seconds) * time.Second
|
|
}
|