实现基本的反向代理

This commit is contained in:
GoEdgeLab
2020-09-27 15:26:06 +08:00
parent 47a1a477f3
commit ee2281b581
13 changed files with 522 additions and 60 deletions

26
internal/utils/time.go Normal file
View File

@@ -0,0 +1,26 @@
package utils
import (
"time"
)
var unixTime = time.Now().Unix()
var unixTimerIsReady = false
func init() {
ticker := time.NewTicker(500 * time.Millisecond)
go func() {
for range ticker.C {
unixTimerIsReady = true
unixTime = time.Now().Unix()
}
}()
}
// 最快获取时间戳的方式,通常用在不需要特别精确时间戳的场景
func UnixTime() int64 {
if unixTimerIsReady {
return unixTime
}
return time.Now().Unix()
}