diff --git a/README.MD b/README.MD index 1ea4b85d..454b7703 100644 --- a/README.MD +++ b/README.MD @@ -109,8 +109,12 @@ serve_limit: dashboard: # 是否启用 enable: true - # PWA 的名称 + # PWA 的名称, 在桌面设备上显示 pwa-name: GoOpemBmclApi Dashboard + # PWA 短名称, 在移动设备上显示 + pwa-short_name: GOBA Dash + # PWA 描述 + pwa-description: Go-Openbmclapi Internal Dashboard ## 特殊要求: 重定向到 OSS oss: diff --git a/config.go b/config.go index 0fae0f88..15605df8 100644 --- a/config.go +++ b/config.go @@ -44,8 +44,10 @@ type ServeLimitConfig struct { } type DashboardConfig struct { - Enable bool `yaml:"enable"` - PwaName string `yaml:"pwa-name"` + Enable bool `yaml:"enable"` + PwaName string `yaml:"pwa-name"` + PwaShortName string `yaml:"pwa-short_name"` + PwaDesc string `yaml:"pwa-description"` } type OSSConfig struct { @@ -86,58 +88,64 @@ type Config struct { func (cfg *Config) applyWebManifest(manifest map[string]any) { if cfg.Dashboard.Enable { manifest["name"] = cfg.Dashboard.PwaName + manifest["short_name"] = cfg.Dashboard.PwaShortName + manifest["description"] = cfg.Dashboard.PwaDesc } } -func readConfig() (config Config) { - const configPath = "config.yaml" - - config = Config{ - Debug: false, - RecordServeInfo: false, - Nohttps: false, - NoOpen: false, - NoHeavyCheck: false, - TrustedXForwardedFor: false, - PublicHost: "example.com", - PublicPort: 8080, - Port: 4000, - ClusterId: "${CLUSTER_ID}", - ClusterSecret: "${CLUSTER_SECRET}", - SyncInterval: 10, - KeepaliveTimeout: 10, - DownloadMaxConn: 64, - UseGzip: false, - ServeLimit: ServeLimitConfig{ - Enable: false, - MaxConn: 16384, - UploadRate: 1024 * 12, // 12MB - }, - - Dashboard: DashboardConfig{ - Enable: true, - PwaName: "GoOpemBmclApi Dashboard", - }, - - Oss: OSSConfig{ - Enable: false, - List: []*OSSItem{ - { - FolderPath: "oss_mirror", - RedirectBase: "https://oss.example.com/base/paths", - SkipMeasureGen: false, - }, +var defaultConfig = Config{ + Debug: false, + RecordServeInfo: false, + Nohttps: false, + NoOpen: false, + NoHeavyCheck: false, + TrustedXForwardedFor: false, + PublicHost: "example.com", + PublicPort: 8080, + Port: 4000, + ClusterId: "${CLUSTER_ID}", + ClusterSecret: "${CLUSTER_SECRET}", + SyncInterval: 10, + KeepaliveTimeout: 10, + DownloadMaxConn: 64, + UseGzip: false, + ServeLimit: ServeLimitConfig{ + Enable: false, + MaxConn: 16384, + UploadRate: 1024 * 12, // 12MB + }, + + Dashboard: DashboardConfig{ + Enable: true, + PwaName: "GoOpemBmclApi Dashboard", + PwaShortName: "GOBA Dash", + PwaDesc: "Go-Openbmclapi Internal Dashboard", + }, + + Oss: OSSConfig{ + Enable: false, + List: []*OSSItem{ + { + FolderPath: "oss_mirror", + RedirectBase: "https://oss.example.com/base/paths", + SkipMeasureGen: false, }, }, + }, + + Hijack: HijackConfig{ + Enable: false, + ServerHost: "", + ServerPort: 8090, + Path: "__hijack", + AntiHijackDNS: "8.8.8.8:53", + }, +} - Hijack: HijackConfig{ - Enable: false, - ServerHost: "", - ServerPort: 8090, - Path: "__hijack", - AntiHijackDNS: "8.8.8.8:53", - }, - } +func readConfig() (config Config) { + const configPath = "config.yaml" + + config = defaultConfig data, err := os.ReadFile(configPath) notexists := false diff --git a/config.yaml b/config.yaml index 6f9923df..9f52b18f 100644 --- a/config.yaml +++ b/config.yaml @@ -20,6 +20,8 @@ serve_limit: dashboard: enable: true pwa-name: GoOpemBmclApi Dashboard + pwa-short_name: GOBA Dash + pwa-description: Go-Openbmclapi Internal Dashboard oss: enable: false list: diff --git a/main.go b/main.go index c6da387e..0b45097b 100644 --- a/main.go +++ b/main.go @@ -342,13 +342,13 @@ START: } } - logDebugf("Receiving signals") - signal.Notify(signalCh, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) - if !cluster.Connect(ctx) { os.Exit(1) } + logDebugf("Receiving signals") + signal.Notify(signalCh, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) + clusterSvr := &http.Server{ Addr: fmt.Sprintf("%s:%d", "0.0.0.0", config.Port), ReadTimeout: 10 * time.Second,