添加时区

This commit is contained in:
wood chen 2024-09-18 01:48:46 +08:00
parent 8775ac9b7c
commit bb3a9c601c
2 changed files with 21 additions and 0 deletions

View File

@ -4,6 +4,9 @@ FROM alpine:latest
# 安装 ca-certificates通常需要用于 HTTPS # 安装 ca-certificates通常需要用于 HTTPS
RUN apk --no-cache add ca-certificates RUN apk --no-cache add ca-certificates
# 设置时区
ENV TZ=Asia/Singapore
# 创建工作目录 # 创建工作目录
WORKDIR /root/ WORKDIR /root/

18
main.go
View File

@ -17,6 +17,24 @@ var (
) )
func init() { func init() {
// 设置时区
setTimeZone()
// 其他初始化逻辑
initializeVariables()
}
func setTimeZone() {
loc, err := time.LoadLocation("Asia/Singapore")
if err != nil {
log.Printf("Error loading time zone 'Asia/Singapore': %v", err)
log.Println("Falling back to UTC")
loc = time.UTC
}
time.Local = loc
}
func initializeVariables() {
BOT_TOKEN = os.Getenv("BOT_TOKEN") BOT_TOKEN = os.Getenv("BOT_TOKEN")
adminIDStr := os.Getenv("ADMIN_ID") adminIDStr := os.Getenv("ADMIN_ID")
var err error var err error