util

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2022 License: MIT Imports: 19 Imported by: 2

Documentation

Index

Constants

View Source
const (
	Invalid   = 0
	SECP256K1 = 1
	ED25519   = 2
	SM2       = 3
)

Variables

View Source
var (
	ErrTransToInt64 = errors.New("transfer type int64 error")
	ErrTransToInt32 = errors.New("transfer type int32 error")
)

Functions

func CheckTimeOut

func CheckTimeOut(tm int64, timeout time.Duration) bool

tm 时间,单位毫秒

func Decode

func Decode(c interface{}) error

func GetSummary

func GetSummary(i interface{}) ([]byte, error)

得到摘要

func HexDecode

func HexDecode(in string) ([]byte, error)

兼容0x格式

func HongKong

func HongKong() *time.Location

HongKong returns Hong Kong *time.Location.

func Local

func Local() *time.Location

Local returns Local *time.Location.

func Location

func Location(name string) *time.Location

Location returns *time.Location by location name.

func Secp256k1Verify

func Secp256k1Verify(msg, sig, pubKey []byte) (b bool)

func Shanghai

func Shanghai() *time.Location

Shanghai returns Shanghai *time.Location.

func Sleep

func Sleep(n int64)

Sleep pauses the current goroutine for at least n second.

func SleepMicro

func SleepMicro(n int64)

SleepMicro pauses the current goroutine for at least n microsecond.

func SleepMilli

func SleepMilli(n int64)

SleepMilli pauses the current goroutine for at least n millisecond.

func StringToTime

func StringToTime(str, format string, location ...*time.Location) (time.Time, error)

StringToTime returns time.Time representation of str value parsed according to layout.

func StringToTimeDefault

func StringToTimeDefault(str string) time.Time

func StringToUnix

func StringToUnix(str, format string, location ...*time.Location) int64

StringToUnix returns unix second timestamp representation of str value parsed according to layout. If str parsed err, it returns now unix second timestamp.

func TimeNowDate

func TimeNowDate(location ...*time.Location) string

TimeNowDate returns a date representation of now time value.

func TimeNowDateTime

func TimeNowDateTime(location ...*time.Location) string

TimeNowDateTime returns a datetime representation of now time value.

func TimeNowFormat

func TimeNowFormat(layout string, location ...*time.Location) string

TimeNowFormat returns a textual representation of now time value formatted according to layout.

func TimeNowUnix

func TimeNowUnix(location ...*time.Location) int64

TimeNowUnix returns now unix second timestamp.

func TimeNowUnixMicro

func TimeNowUnixMicro(location ...*time.Location) int64

TimeNowUnixMicro returns now unix microsecond timestamp.

func TimeNowUnixMilli

func TimeNowUnixMilli(location ...*time.Location) int64

TimeNowUnixMilli returns now unix millisecond timestamp.

func TimeNowUnixNano

func TimeNowUnixNano(location ...*time.Location) int64

TimeNowUnixNano returns now unix nanosecond timestamp.

func ToBool

func ToBool(val interface{}) bool

func ToFloat64

func ToFloat64(val interface{}) float64

func ToInt

func ToInt(val interface{}) int

func ToInt32

func ToInt32(o interface{}) int32

func ToInt32E

func ToInt32E(o interface{}) (int32, error)

func ToInt64

func ToInt64(val interface{}) int64

func ToInt64E

func ToInt64E(val interface{}) (int64, error)

func ToString

func ToString(val interface{}) string

func ToUInt32

func ToUInt32(val interface{}) uint32

func ToUInt64

func ToUInt64(val interface{}) uint64

func TypeToString

func TypeToString(val interface{}) string

func UTC

func UTC() *time.Location

UTC returns UTC *time.Location.

func UnixAddDate

func UnixAddDate(timestamp int64, years, months, days int) time.Time

UnixAddDate returns time.Time after unix timestamp has been added date.

func UnixAddDays

func UnixAddDays(timestamp int64, days int) time.Time

UnixAddDays returns time.Time after unix timestamp has been added days.

func UnixAddMonths

func UnixAddMonths(timestamp int64, months int) time.Time

UnixAddMonths returns time.Time after unix timestamp has been added months.

func UnixAddYears

func UnixAddYears(timestamp int64, years int) time.Time

UnixAddYears returns time.Time after unix timestamp has been added years.

func UnixAfter

func UnixAfter(timestamp1 int64, timestamp2 int64) bool

UnixAfter reports whether timestamp1 is after timestamp2.

func UnixBefore

func UnixBefore(timestamp1 int64, timestamp2 int64) bool

UnixBefore reports whether timestamp1 is before timestamp2.

func UnixDifferDays

func UnixDifferDays(timestamp1 int64, timestamp2 int64) int

UnixDifferDays returns the number of days between two timestamp.

func UnixDifferHours

func UnixDifferHours(timestamp1 int64, timestamp2 int64) float64

UnixDifferHours returns the number of hours between two timestamp.

func UnixEqual

func UnixEqual(timestamp1 int64, timestamp2 int64) bool

UnixEqual reports whether timestamp1 is equal timestamp2.

func UnixToTime

func UnixToTime(timestamp int64) time.Time

UnixToTime returns time.Time by unix timestamp.

Types

type Snowflake

type Snowflake struct {
	sync.Mutex // 互斥锁,用于确保并发安全
	// contains filtered or unexported fields
}

Snowflake 定义一个Snowflake节点所需要的基本参数

func NewSnowflake

func NewSnowflake(nodeId int64, location ...*time.Location) (*Snowflake, error)

NewSnowflake 实例化一个Snowflake节点

func (*Snowflake) NextId

func (s *Snowflake) NextId(location ...*time.Location) int64

NextId 获取唯一id

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL