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 ¶
func CurrentTimeMillsWithTicker() uint64
func CurrentTimeNano ¶
func CurrentTimeNano() uint64
Returns the current Unix timestamp in nanoseconds.
func FileExists ¶
func Float64Equals ¶
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 ¶
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 ¶
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 ¶
Sleep pauses the current goroutine for at least the duration d. A negative or zero duration causes Sleep to return immediately.
func StartTimeTicker ¶
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 ¶
type Clock interface { Now() time.Time Sleep(d time.Duration) CurrentTimeMillis() uint64 CurrentTimeNano() uint64 }
func CurrentClock ¶
func CurrentClock() Clock
CurrentClock returns the current clock used by util package.
type MockClock ¶
type MockClock struct {
// contains filtered or unexported fields
}
MockClock is used for testing.
func NewMockClock ¶
func NewMockClock() *MockClock
func (*MockClock) CurrentTimeMillis ¶
func (*MockClock) CurrentTimeNano ¶
type MockTicker ¶
type MockTicker struct {
// contains filtered or unexported fields
}
MockTicker is usually used for testing. MockTicker and MockClock are usually used together.
func NewMockTicker ¶
func NewMockTicker(d time.Duration) *MockTicker
func (*MockTicker) C ¶
func (t *MockTicker) C() <-chan time.Time
func (*MockTicker) Stop ¶
func (t *MockTicker) Stop()
type MockTickerCreator ¶
type MockTickerCreator struct{}
MockTickerCreator is used create MockTicker which is usually used for testing. MockTickerCreator and MockClock are usually used together.
func NewMockTickerCreator ¶
func NewMockTickerCreator() *MockTickerCreator
type RealClock ¶
type RealClock struct{}
RealClock wraps some APIs of time package.
func NewRealClock ¶
func NewRealClock() *RealClock
func (*RealClock) CurrentTimeMillis ¶
func (*RealClock) CurrentTimeNano ¶
type RealTicker ¶
type RealTicker struct {
// contains filtered or unexported fields
}
RealTicker wraps time.Ticker.
func NewRealTicker ¶
func NewRealTicker(d time.Duration) *RealTicker
func (*RealTicker) C ¶
func (t *RealTicker) C() <-chan time.Time
func (*RealTicker) Stop ¶
func (t *RealTicker) Stop()
type RealTickerCreator ¶
type RealTickerCreator struct{}
RealTickerCreator is used to creates RealTicker which wraps time.Ticker.
func NewRealTickerCreator ¶
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 ¶
TickerCreator is used to create Ticker.
func CurrentTickerCreator ¶
func CurrentTickerCreator() TickerCreator
CurrentTickerCreator returns the current ticker creator used by util package.