service.xpcool.com/main.go
夏犀麟 4b3c00270f
Some checks failed
Build and Deploy (service.xpcool.com) / build-and-deploy (push) Failing after 31s
feat(i18n): 中文化校验提示与服务层错误信息
将 api 层校验规则提示语、service 层 gerror.Wrap 与 response.Error
错误信息、panic 未注册提示统一改为中文,并同步中文化 cmd 路由注释
与变更记录。仅涉及注释、文档与字符串改动,无业务逻辑变更。
2026-09-13 23:22:46 +08:00

51 lines
1.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Package main 是服务启动入口。
//
// 启动前的配置兜底:本仓库不提供默认的 config.yaml仅按环境提供
// config.dev.yaml / config.test.yaml / config.prod.yaml框架默认却要找
// config.yaml导致直接运行时报「config not found」。这里在加载配置前
// 若未通过 GF_GCFG_FILE 指定文件名,则自动回落到 config.dev.yaml。
//
// 因此以下方式均可直接启动,无需手动传环境变量:
// - GoLand 直接点运行(含自动生成的临时配置)
// - 命令行 go run main.go / 双击二进制
//
// 如需切换环境,显式设置环境变量即可覆盖默认行为:
//
// GF_GCFG_FILE=config.test.yaml # 或 config.prod.yaml
package main
import (
_ "github.com/gogf/gf/contrib/drivers/mysql/v2" // MySQL 驱动gdb 必需
"github.com/gogf/gf/v2/os/gctx"
"github.com/gogf/gf/v2/os/genv"
"service.xpcool.com/internal/cmd"
)
const (
// envKeyForFile 是 GoFrame 官方的「配置文件名」环境变量。
// 框架在初始化文件适配器gcfg.NewAdapterFile时读取它用于决定加载哪个配置文件。
envKeyForFile = "GF_GCFG_FILE"
// envKeyForPath 是 GoFrame 官方的「配置文件目录」环境变量。
envKeyForPath = "GF_GCFG_PATH"
// defaultConfigFile 是未显式指定配置文件时使用的默认文件名(开发环境)。
defaultConfigFile = "config.dev.yaml"
)
func main() {
injectDefaultConfigFile()
cmd.Main.Run(gctx.GetInitCtx())
}
// injectDefaultConfigFile 在配置系统初始化前,兜底指定默认配置文件。
//
// 仅在「调用方未显式指定配置文件或目录」时才写入默认值,
// 以免覆盖使用者通过环境变量或命令行做出的选择。
func injectDefaultConfigFile() {
if !genv.Get(envKeyForFile).IsEmpty() || !genv.Get(envKeyForPath).IsEmpty() {
return
}
_ = genv.Set(envKeyForFile, defaultConfigFile)
}