This commit is contained in:
yoan
2024-08-21 12:19:12 +08:00
commit 50fa238d88
89 changed files with 11835 additions and 0 deletions

19
internal/utils/app/app.go Normal file
View 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
}

View 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
}

View 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)
}

View 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")
}