diff --git a/Dockerfile b/Dockerfile index d828975..818a557 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,6 +26,7 @@ FROM alpine #设置时区 RUN apk add --no-cache tzdata ENV TZ=Asia/Shanghai +ENV LANG=C.UTF-8 WORKDIR /app # 将编译好的二进制文件从构建阶段复制到运行阶段 diff --git a/main.go b/main.go index 736894f..508e4ac 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( "qteam/config" _ "qteam/docs" "qteam/rpc" + "time" _ "github.com/go-sql-driver/mysql" _ "github.com/qit-team/snow-core/cache/rediscache" @@ -101,7 +102,13 @@ func startServer(opts *config.Options) (err error) { if err != nil { return } - + // 加载上海时区 + shanghaiTimeZone, err := time.LoadLocation("Asia/Shanghai") + if err != nil { + panic(fmt.Sprintf("无法加载上海时区: %v", err)) + } + // 设置时区(例如,用于处理时间) + time.Local = shanghaiTimeZone // 这会改变默认的本地时区 pidFile := opts.GenPidFile() //根据启动命令行参数,决定启动哪种服务模式 switch opts.App {