feat: support monitor cli override flags

This commit is contained in:
2026-04-04 07:53:34 +00:00
parent 6e60fae559
commit 65f521dce0
2 changed files with 59 additions and 1 deletions

View File

@@ -17,7 +17,21 @@ type Config struct {
MonitorPort int `json:"monitorPort"`
}
type Overrides struct {
BackendURL string
Identifier string
APIKey string
ReportIntervalSec int
LogLevel string
RootFS string
MonitorPort int
}
func Load(path string) (Config, error) {
return LoadWithOverrides(path, Overrides{})
}
func LoadWithOverrides(path string, overrides Overrides) (Config, error) {
cfg := Config{
BackendURL: getenvAny([]string{"HF_MONITER_BACKEND_URL", "HF_MONITOR_BACKEND_URL"}, "https://monitor.hangman-lab.top"),
Identifier: getenvAny([]string{"HF_MONITER_IDENTIFIER", "HF_MONITOR_IDENTIFIER"}, hostnameOr("unknown-host")),
@@ -46,6 +60,28 @@ func Load(path string) (Config, error) {
cfg.RootFS = getenvAny([]string{"HF_MONITER_ROOTFS", "HF_MONITOR_ROOTFS"}, cfg.RootFS)
cfg.MonitorPort = getenvIntAny([]string{"MONITOR_PORT", "HF_MONITOR_PORT"}, cfg.MonitorPort)
if overrides.BackendURL != "" {
cfg.BackendURL = overrides.BackendURL
}
if overrides.Identifier != "" {
cfg.Identifier = overrides.Identifier
}
if overrides.APIKey != "" {
cfg.APIKey = overrides.APIKey
}
if overrides.ReportIntervalSec > 0 {
cfg.ReportIntervalSec = overrides.ReportIntervalSec
}
if overrides.LogLevel != "" {
cfg.LogLevel = overrides.LogLevel
}
if overrides.RootFS != "" {
cfg.RootFS = overrides.RootFS
}
if overrides.MonitorPort > 0 {
cfg.MonitorPort = overrides.MonitorPort
}
if cfg.BackendURL == "" {
return cfg, fmt.Errorf("backendUrl is required")
}