mirror of
https://github.com/gofiber/fiber.git
synced 2025-05-31 11:52:41 +00:00
* internal: revert linting changes Changes to the internal package should not have been made in 167a8b5e9421e0ab51fbf44c5621632f4a1a90c5. * middleware/monitor: revert changes to exported field "ChartJSURL" This is a breaking change introduced in 167a8b5e9421e0ab51fbf44c5621632f4a1a90c5. * middleware/monitor: fix error checking Fix the errorenous error checking introduced in 167a8b5e9421e0ab51fbf44c5621632f4a1a90c5. * 🐛 Bug: Fix issues introduced in linting PR #2319 * 🐛 Bug: Fix issues introduced in linting PR #2319 * Bug: Fix issues introduced in linting PR #2319 --------- Co-authored-by: René Werner <rene@gofiber.io>
33 lines
836 B
Go
33 lines
836 B
Go
package utils
|
|
|
|
import (
|
|
"sync"
|
|
"sync/atomic"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
timestampTimer sync.Once
|
|
// Timestamp please start the timer function before you use this value
|
|
// please load the value with atomic `atomic.LoadUint32(&utils.Timestamp)`
|
|
Timestamp uint32
|
|
)
|
|
|
|
// StartTimeStampUpdater starts a concurrent function which stores the timestamp to an atomic value per second,
|
|
// which is much better for performance than determining it at runtime each time
|
|
func StartTimeStampUpdater() {
|
|
timestampTimer.Do(func() {
|
|
// set initial value
|
|
atomic.StoreUint32(&Timestamp, uint32(time.Now().Unix()))
|
|
go func(sleep time.Duration) {
|
|
ticker := time.NewTicker(sleep)
|
|
defer ticker.Stop()
|
|
|
|
for t := range ticker.C {
|
|
// update timestamp
|
|
atomic.StoreUint32(&Timestamp, uint32(t.Unix()))
|
|
}
|
|
}(1 * time.Second) // duration
|
|
})
|
|
}
|