添加前端

This commit is contained in:
2026-06-03 18:31:15 +08:00
parent a3ad72c140
commit 9748a1e681
29 changed files with 2506 additions and 20 deletions
+55
View File
@@ -16,6 +16,7 @@ type config struct {
MQTT mqttConfig `yaml:"mqtt"`
Meshtastic meshtasticConfig `yaml:"meshtastic"`
Database databaseConfig `yaml:"database"`
Web webConfig `yaml:"web"`
key []byte
}
@@ -49,10 +50,18 @@ type mysqlConfig struct {
DSN string `yaml:"dsn"`
}
type webConfig struct {
Enabled bool `yaml:"enabled"`
Host string `yaml:"host"`
Port int `yaml:"port"`
StaticDir string `yaml:"static_dir"`
}
type rawConfig struct {
MQTT *rawMQTTConfig `yaml:"mqtt"`
Meshtastic *rawMeshtasticConfig `yaml:"meshtastic"`
Database *rawDatabaseConfig `yaml:"database"`
Web *rawWebConfig `yaml:"web"`
}
type rawMQTTConfig struct {
@@ -85,6 +94,13 @@ type rawMySQLConfig struct {
DSN *string `yaml:"dsn"`
}
type rawWebConfig struct {
Enabled *bool `yaml:"enabled"`
Host *string `yaml:"host"`
Port *int `yaml:"port"`
StaticDir *string `yaml:"static_dir"`
}
// defaultConfig 返回内置默认配置。
func defaultConfig() *config {
return &config{
@@ -105,6 +121,12 @@ func defaultConfig() *config {
SQLite: sqliteConfig{Path: defaultSQLitePath()},
MySQL: mysqlConfig{DSN: ""},
},
Web: webConfig{
Enabled: true,
Host: "0.0.0.0",
Port: 8080,
StaticDir: "./dist",
},
}
}
@@ -245,6 +267,31 @@ func normalizeConfig(raw rawConfig) (*config, bool) {
}
}
if raw.Web == nil {
changed = true
} else {
if raw.Web.Enabled == nil {
changed = true
} else {
cfg.Web.Enabled = *raw.Web.Enabled
}
if raw.Web.Host == nil {
changed = true
} else {
cfg.Web.Host = *raw.Web.Host
}
if raw.Web.Port == nil {
changed = true
} else {
cfg.Web.Port = *raw.Web.Port
}
if raw.Web.StaticDir == nil {
changed = true
} else {
cfg.Web.StaticDir = *raw.Web.StaticDir
}
}
return cfg, changed
}
@@ -264,6 +311,14 @@ func validateConfig(cfg *config) error {
default:
return fmt.Errorf("invalid database.driver %q: must be sqlite or mysql", cfg.Database.Driver)
}
if cfg.Web.Enabled {
if cfg.Web.Port <= 0 || cfg.Web.Port > 65535 {
return fmt.Errorf("invalid web port %d: must be 1-65535", cfg.Web.Port)
}
if cfg.Web.StaticDir == "" {
return fmt.Errorf("web.static_dir is required when web is enabled")
}
}
return nil
}