config file error

This commit is contained in:
2024-11-01 00:29:35 +08:00
parent dcac6578dc
commit 431ab13673
4 changed files with 9 additions and 5 deletions

View File

@@ -14,15 +14,19 @@ COPY . .
# 构建可执行文件 # 构建可执行文件
RUN CGO_ENABLED=0 GOOS=linux go build -v -o app . RUN CGO_ENABLED=0 GOOS=linux go build -v -o app .
# 使用一个更小的基础镜像来减小最终镜像的大小 # 使用一个更小的基础镜像来减小最终镜像的大小
FROM alpine:latest FROM alpine:latest
# 时区设置成当前时区
RUN apk add --no-cache tzdata
ENV TZ="Asia/Shanghai"
# 设置工作目录 # 设置工作目录
WORKDIR /root/ WORKDIR /root/
# 从构建阶段复制可执行文件 # 从构建阶段复制可执行文件
COPY --from=builder /app/app . COPY --from=builder /app/app .
# 在容器目录 /root/ 创建一个目录 为config
RUN mkdir conf .
COPY --from=builder /app/conf/ ./conf/
# 暴露端口 # 暴露端口
EXPOSE 8080 EXPOSE 8080

View File

@@ -85,6 +85,7 @@ func SetUp1() {
mysqlHost := viper.GetString("mysql.Host") mysqlHost := viper.GetString("mysql.Host")
jwtSecretKey := viper.GetString("jwt.SecretKey") jwtSecretKey := viper.GetString("jwt.SecretKey")
serverPort := viper.GetInt("server.Port") serverPort := viper.GetInt("server.Port")
DataBase = viper.Get("database")
templateGlob := viper.GetString("project.TemplateGlob") templateGlob := viper.GetString("project.TemplateGlob")
// 打印获取到的配置值 // 打印获取到的配置值

View File

@@ -1,4 +1,4 @@
mysql: database:
Type: mysql Type: mysql
Host: 127.0.0.1 Host: 127.0.0.1
Port: 3306 Port: 3306

View File

@@ -36,7 +36,6 @@ func init() {
flag.Parse() flag.Parse()
conf.SetUp() conf.SetUp()
conf.SetUp1()
models.SetUp(isOrmDebug) models.SetUp(isOrmDebug)
} }