Skip to content

Commit

Permalink
support short name and dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxkad committed Jan 28, 2024
1 parent 3d3192a commit 9bb7dcb
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 52 deletions.
6 changes: 5 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
104 changes: 56 additions & 48 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 9bb7dcb

Please sign in to comment.