init
This commit is contained in:
19
internal/utils/app/app.go
Normal file
19
internal/utils/app/app.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/pocketbase/pocketbase"
|
||||
)
|
||||
|
||||
var instance *pocketbase.PocketBase
|
||||
|
||||
var intanceOnce sync.Once
|
||||
|
||||
func GetApp() *pocketbase.PocketBase {
|
||||
intanceOnce.Do(func() {
|
||||
instance = pocketbase.New()
|
||||
})
|
||||
|
||||
return instance
|
||||
}
|
||||
19
internal/utils/app/schedule.go
Normal file
19
internal/utils/app/schedule.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/pocketbase/pocketbase/tools/cron"
|
||||
)
|
||||
|
||||
var schedulerOnce sync.Once
|
||||
|
||||
var scheduler *cron.Cron
|
||||
|
||||
func GetScheduler() *cron.Cron {
|
||||
schedulerOnce.Do(func() {
|
||||
scheduler = cron.New()
|
||||
})
|
||||
|
||||
return scheduler
|
||||
}
|
||||
23
internal/utils/rand/rand.go
Normal file
23
internal/utils/rand/rand.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package rand
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
// RandStr 随机生成指定长度字符串
|
||||
func RandStr(n int) string {
|
||||
seed := time.Now().UnixNano()
|
||||
source := rand.NewSource(seed)
|
||||
random := rand.New(source)
|
||||
|
||||
letters := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
||||
|
||||
// 使用循环生成指定长度的字符串
|
||||
result := make([]rune, n)
|
||||
for i := range result {
|
||||
result[i] = letters[random.Intn(len(letters))]
|
||||
}
|
||||
|
||||
return string(result)
|
||||
}
|
||||
15
internal/utils/xtime/time.go
Normal file
15
internal/utils/xtime/time.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package xtime
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func BeijingTimeStr() string {
|
||||
location, _ := time.LoadLocation("Asia/Shanghai")
|
||||
|
||||
// 获取当前时间
|
||||
now := time.Now().In(location)
|
||||
|
||||
// 格式化为字符串
|
||||
return now.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
Reference in New Issue
Block a user