Documentation ¶
Index ¶
- Constants
- func CreateDirIfNotExists(dirname string) error
- func CurrentTimeMillis() uint64
- func CurrentTimeMillsWithTicker() uint64
- func CurrentTimeNano() uint64
- func FileExists(name string) (b bool, err error)
- func FilePosition(file *os.File) (int64, error)
- func Float64Equals(x, y float64) bool
- func FormatDate(tsMillis uint64) string
- func FormatTimeMillis(tsMillis uint64) string
- func IsBlank(s string) bool
- func NewUuid() string
- func Now() time.Time
- func RunWithRecover(f func())
- func SetClock(c Clock)
- func SetTickerCreator(tc TickerCreator)
- func Sleep(d time.Duration)
- func StartTimeTicker()
- type AtomicBool
- type Clock
- type MockClock
- type MockTicker
- type MockTickerCreator
- type RealClock
- type RealTicker
- type RealTickerCreator
- type SliceHeader
- type StringHeader
- type Ticker
- type TickerCreator
Constants ¶
const ( TimeFormat = "2006-01-02 15:04:05" DateFormat = "2006-01-02" UnixTimeUnitOffset = uint64(time.Millisecond / time.Nanosecond) )
Variables ¶
This section is empty.
Functions ¶
func CreateDirIfNotExists ¶
func CurrentTimeMillis ¶
func CurrentTimeMillis() uint64
Returns the current Unix timestamp in milliseconds.
func CurrentTimeMillsWithTicker ¶ added in v0.4.0
func CurrentTimeMillsWithTicker() uint64
func CurrentTimeNano ¶
func CurrentTimeNano() uint64
Returns the current Unix timestamp in nanoseconds.
func FileExists ¶
func Float64Equals ¶ added in v0.6.0
func FormatDate ¶
FormatDate formats Unix timestamp (ms) to date string
func FormatTimeMillis ¶
FormatTimeMillis formats Unix timestamp (ms) to time string.
func RunWithRecover ¶
func RunWithRecover(f func())
func SetClock ¶ added in v1.0.3
func SetClock(c Clock)
SetClock sets the clock used by util package. In general, no need to set it. It is usually used for testing.
func SetTickerCreator ¶ added in v1.0.3
func SetTickerCreator(tc TickerCreator)
SetClock sets the ticker creator used by util package. In general, no need to set it. It is usually used for testing.
func Sleep ¶ added in v1.0.3
Sleep pauses the current goroutine for at least the duration d. A negative or zero duration causes Sleep to return immediately.
func StartTimeTicker ¶ added in v0.4.0
func StartTimeTicker()
StartTimeTicker starts a background task that caches current timestamp per millisecond, which may provide better performance in high-concurrency scenarios.
Types ¶
type AtomicBool ¶
type AtomicBool struct {
// contains filtered or unexported fields
}
func (*AtomicBool) CompareAndSet ¶
func (b *AtomicBool) CompareAndSet(old, new bool) bool
func (*AtomicBool) Get ¶
func (b *AtomicBool) Get() bool
func (*AtomicBool) Set ¶
func (b *AtomicBool) Set(value bool)
type Clock ¶ added in v1.0.3
type Clock interface { Now() time.Time Sleep(d time.Duration) CurrentTimeMillis() uint64 CurrentTimeNano() uint64 }
func CurrentClock ¶ added in v1.0.3
func CurrentClock() Clock
CurrentClock returns the current clock used by util package.
type MockClock ¶ added in v1.0.3
type MockClock struct {
// contains filtered or unexported fields
}
MockClock is used for testing.
func NewMockClock ¶ added in v1.0.3
func NewMockClock() *MockClock
func (*MockClock) CurrentTimeMillis ¶ added in v1.0.3
func (*MockClock) CurrentTimeNano ¶ added in v1.0.3
type MockTicker ¶ added in v1.0.3
type MockTicker struct {
// contains filtered or unexported fields
}
MockTicker is usually used for testing. MockTicker and MockClock are usually used together.
func NewMockTicker ¶ added in v1.0.3
func NewMockTicker(d time.Duration) *MockTicker
func (*MockTicker) C ¶ added in v1.0.3
func (t *MockTicker) C() <-chan time.Time
func (*MockTicker) Stop ¶ added in v1.0.3
func (t *MockTicker) Stop()
type MockTickerCreator ¶ added in v1.0.3
type MockTickerCreator struct{}
MockTickerCreator is used create MockTicker which is usually used for testing. MockTickerCreator and MockClock are usually used together.
func NewMockTickerCreator ¶ added in v1.0.3
func NewMockTickerCreator() *MockTickerCreator
type RealClock ¶ added in v1.0.3
type RealClock struct{}
RealClock wraps some APIs of time package.
func NewRealClock ¶ added in v1.0.3
func NewRealClock() *RealClock
func (*RealClock) CurrentTimeMillis ¶ added in v1.0.3
func (*RealClock) CurrentTimeNano ¶ added in v1.0.3
type RealTicker ¶ added in v1.0.3
type RealTicker struct {
// contains filtered or unexported fields
}
RealTicker wraps time.Ticker.
func NewRealTicker ¶ added in v1.0.3
func NewRealTicker(d time.Duration) *RealTicker
func (*RealTicker) C ¶ added in v1.0.3
func (t *RealTicker) C() <-chan time.Time
func (*RealTicker) Stop ¶ added in v1.0.3
func (t *RealTicker) Stop()
type RealTickerCreator ¶ added in v1.0.3
type RealTickerCreator struct{}
RealTickerCreator is used to creates RealTicker which wraps time.Ticker.
func NewRealTickerCreator ¶ added in v1.0.3
func NewRealTickerCreator() *RealTickerCreator
type SliceHeader ¶
SliceHeader is a safe version of SliceHeader used within this project.
type StringHeader ¶
StringHeader is a safe version of StringHeader used within this project.
type TickerCreator ¶ added in v1.0.3
TickerCreator is used to create Ticker.
func CurrentTickerCreator ¶ added in v1.0.3
func CurrentTickerCreator() TickerCreator
CurrentTickerCreator returns the current ticker creator used by util package.