mirror of
https://github.com/bjdgyc/anylink.git
synced 2025-08-08 00:31:17 +08:00
添加ip审计功能
This commit is contained in:
20
server/pkg/utils/unsafe.go
Normal file
20
server/pkg/utils/unsafe.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// BytesToString converts byte slice to string.
|
||||
func BytesToString(b []byte) string {
|
||||
return *(*string)(unsafe.Pointer(&b))
|
||||
}
|
||||
|
||||
// StringToBytes converts string to byte slice.
|
||||
func StringToBytes(s string) []byte {
|
||||
return *(*[]byte)(unsafe.Pointer(
|
||||
&struct {
|
||||
string
|
||||
Cap int
|
||||
}{s, len(s)},
|
||||
))
|
||||
}
|
@@ -3,11 +3,30 @@ package utils
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
// 每秒时间缓存
|
||||
timeNowSec = &atomic.Value{}
|
||||
)
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
|
||||
timeNowSec.Store(time.Now())
|
||||
go func() {
|
||||
tick := time.NewTicker(time.Second * 1)
|
||||
for c := range tick.C {
|
||||
timeNowSec.Store(c)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func NowSec() time.Time {
|
||||
t := timeNowSec.Load()
|
||||
return t.(time.Time)
|
||||
}
|
||||
|
||||
func InArrStr(arr []string, str string) bool {
|
||||
|
Reference in New Issue
Block a user