feat: 可选社区上报与官方精选展柜
默认关闭,仪表盘一键开关;枢纽由运维配置收报,人工精选后展示于 /showcase。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -32,6 +32,8 @@ type Config struct {
|
||||
ServiceAction string
|
||||
// 开发模式:后端代理前端请求到 Vite 开发服务器(非内嵌静态资源)
|
||||
DevMode bool
|
||||
// CommunityHub 维护者选项:开启后本站接收其它实例自愿上报(默认关闭)
|
||||
CommunityHub bool
|
||||
}
|
||||
|
||||
// Parse 解析命令行、环境变量与 app.ini,并初始化数据目录
|
||||
@@ -108,6 +110,11 @@ func Parse() (*Config, error) {
|
||||
jwtSecret = strings.TrimSpace(*jwtFlag)
|
||||
}
|
||||
|
||||
communityHub := fileCfg.CommunityHub
|
||||
if v := envBoolOrNil(envCommunityHub); v != nil {
|
||||
communityHub = *v
|
||||
}
|
||||
|
||||
cfg := &Config{
|
||||
WorkPath: workPath,
|
||||
ConfigFile: configFile,
|
||||
@@ -117,6 +124,7 @@ func Parse() (*Config, error) {
|
||||
LogFile: filepath.Join(absData, "jiang13.log"),
|
||||
ServiceAction: action,
|
||||
DevMode: *devFlag,
|
||||
CommunityHub: communityHub,
|
||||
}
|
||||
|
||||
needDirs := action == "" || action == "install"
|
||||
|
||||
@@ -8,11 +8,12 @@ import (
|
||||
|
||||
// 容器 / 编排常用环境变量(优先级:命令行 > 环境变量 > app.ini > 内置默认)
|
||||
const (
|
||||
envWorkPath = "JIANG13_WORK_PATH"
|
||||
envConfig = "JIANG13_CONFIG"
|
||||
envHTTPPort = "JIANG13_HTTP_PORT"
|
||||
envData = "JIANG13_DATA"
|
||||
envJWTSecret = "JIANG13_JWT_SECRET"
|
||||
envWorkPath = "JIANG13_WORK_PATH"
|
||||
envConfig = "JIANG13_CONFIG"
|
||||
envHTTPPort = "JIANG13_HTTP_PORT"
|
||||
envData = "JIANG13_DATA"
|
||||
envJWTSecret = "JIANG13_JWT_SECRET"
|
||||
envCommunityHub = "JIANG13_COMMUNITY_HUB"
|
||||
)
|
||||
|
||||
func envOrDefault(key string) string {
|
||||
@@ -30,3 +31,21 @@ func envIntOrZero(key string) int {
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// envBoolOrNil 解析布尔环境变量;未设置返回 nil
|
||||
func envBoolOrNil(key string) *bool {
|
||||
v := strings.ToLower(envOrDefault(key))
|
||||
if v == "" {
|
||||
return nil
|
||||
}
|
||||
switch v {
|
||||
case "1", "true", "yes", "on":
|
||||
t := true
|
||||
return &t
|
||||
case "0", "false", "no", "off":
|
||||
f := false
|
||||
return &f
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +18,10 @@ const (
|
||||
|
||||
// fileSettings 从 app.ini 读出的原始值(尚未解析为绝对路径)
|
||||
type fileSettings struct {
|
||||
Port int
|
||||
DataRel string
|
||||
JWTSecret string
|
||||
Port int
|
||||
DataRel string
|
||||
JWTSecret string
|
||||
CommunityHub bool // 维护者选项:是否作为社区枢纽收报
|
||||
}
|
||||
|
||||
func defaultFileSettings() fileSettings {
|
||||
@@ -62,6 +63,12 @@ func loadAppINI(path string) (fileSettings, error) {
|
||||
out.JWTSecret = strings.TrimSpace(sec.Key("JWT_SECRET").String())
|
||||
}
|
||||
|
||||
if sec, err := cfg.GetSection("community"); err == nil {
|
||||
if k := sec.Key("HUB"); k.String() != "" {
|
||||
out.CommunityHub = k.MustBool(false)
|
||||
}
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user