feat(web): 新增 web.console_log 开关;data_dir 默认改为 srv/mesh_mqtt_go
- WebConfig 增加 console_log 字段,关闭后 gin 不再向控制台打印 HTTP 访问日志(保留 Recovery)
- 默认值 true;旧配置加载时自动补齐并写回
- defaultDataDirForGOOS 默认目录由 var/lib/mesh_mqtt_go 调整为 srv/mesh_mqtt_go,与 install.sh 中 DATA_DIR=/srv/${SERVICE_NAME} 保持一致
- install.sh 模板同步加入 console_log: true
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -79,6 +79,7 @@ web:
|
|||||||
port: 8080
|
port: 8080
|
||||||
socket_path: ${SOCKET_PATH}
|
socket_path: ${SOCKET_PATH}
|
||||||
static_dir: ${INSTALL_DIR}/dist
|
static_dir: ${INSTALL_DIR}/dist
|
||||||
|
console_log: true
|
||||||
admin:
|
admin:
|
||||||
username: admin
|
username: admin
|
||||||
password: admin
|
password: admin
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ type WebConfig struct {
|
|||||||
SocketPath string `yaml:"socket_path"`
|
SocketPath string `yaml:"socket_path"`
|
||||||
StaticDir string `yaml:"static_dir"`
|
StaticDir string `yaml:"static_dir"`
|
||||||
MapTileCacheDir string `yaml:"map_tile_cache_dir"`
|
MapTileCacheDir string `yaml:"map_tile_cache_dir"`
|
||||||
|
ConsoleLog bool `yaml:"console_log"`
|
||||||
Admin WebAdminConfig `yaml:"admin"`
|
Admin WebAdminConfig `yaml:"admin"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,6 +133,7 @@ type rawWebConfig struct {
|
|||||||
SocketPath *string `yaml:"socket_path"`
|
SocketPath *string `yaml:"socket_path"`
|
||||||
StaticDir *string `yaml:"static_dir"`
|
StaticDir *string `yaml:"static_dir"`
|
||||||
MapTileCacheDir *string `yaml:"map_tile_cache_dir"`
|
MapTileCacheDir *string `yaml:"map_tile_cache_dir"`
|
||||||
|
ConsoleLog *bool `yaml:"console_log"`
|
||||||
Admin *rawWebAdminConfig `yaml:"admin"`
|
Admin *rawWebAdminConfig `yaml:"admin"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,6 +173,7 @@ func Default() *Config {
|
|||||||
SocketPath: defaultWebSocketPath(),
|
SocketPath: defaultWebSocketPath(),
|
||||||
StaticDir: "./dist",
|
StaticDir: "./dist",
|
||||||
MapTileCacheDir: defaultMapTileCacheDir(),
|
MapTileCacheDir: defaultMapTileCacheDir(),
|
||||||
|
ConsoleLog: true,
|
||||||
Admin: WebAdminConfig{
|
Admin: WebAdminConfig{
|
||||||
Username: "admin",
|
Username: "admin",
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
@@ -264,9 +267,9 @@ func defaultDataDir() string {
|
|||||||
|
|
||||||
func defaultDataDirForGOOS(goos string) string {
|
func defaultDataDirForGOOS(goos string) string {
|
||||||
if useRelativeDefaultPath(goos) {
|
if useRelativeDefaultPath(goos) {
|
||||||
return filepath.Join(".", "win", "var", "lib", "mesh_mqtt_go")
|
return filepath.Join(".", "win", "srv", "mesh_mqtt_go")
|
||||||
}
|
}
|
||||||
return filepath.Join(string(filepath.Separator), "var", "lib", "mesh_mqtt_go")
|
return filepath.Join(string(filepath.Separator), "srv", "mesh_mqtt_go")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load 加载配置文件;文件不存在时生成,字段缺失时自动补全并写回。
|
// Load 加载配置文件;文件不存在时生成,字段缺失时自动补全并写回。
|
||||||
@@ -428,6 +431,11 @@ func normalize(raw rawConfig) (*Config, bool) {
|
|||||||
} else {
|
} else {
|
||||||
cfg.Web.MapTileCacheDir = *raw.Web.MapTileCacheDir
|
cfg.Web.MapTileCacheDir = *raw.Web.MapTileCacheDir
|
||||||
}
|
}
|
||||||
|
if raw.Web.ConsoleLog == nil {
|
||||||
|
changed = true
|
||||||
|
} else {
|
||||||
|
cfg.Web.ConsoleLog = *raw.Web.ConsoleLog
|
||||||
|
}
|
||||||
if raw.Web.Admin == nil {
|
if raw.Web.Admin == nil {
|
||||||
changed = true
|
changed = true
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -62,7 +62,11 @@ func ServeUnixSocket(server *http.Server, socketPath string) error {
|
|||||||
|
|
||||||
func NewRouter(cfg configpkg.WebConfig, store *storepkg.Store, sessions *auth.Manager, mqttStatus MQTTStatusProvider, blocking *blockingpkg.Cache, forwarder mqttforwardpkg.Reloader, settings *rspkg.Cache, botSender botpkg.TextSender) *gin.Engine {
|
func NewRouter(cfg configpkg.WebConfig, store *storepkg.Store, sessions *auth.Manager, mqttStatus MQTTStatusProvider, blocking *blockingpkg.Cache, forwarder mqttforwardpkg.Reloader, settings *rspkg.Cache, botSender botpkg.TextSender) *gin.Engine {
|
||||||
r := gin.New()
|
r := gin.New()
|
||||||
|
if cfg.ConsoleLog {
|
||||||
r.Use(gin.Logger(), gin.Recovery())
|
r.Use(gin.Logger(), gin.Recovery())
|
||||||
|
} else {
|
||||||
|
r.Use(gin.Recovery())
|
||||||
|
}
|
||||||
api := r.Group("/api")
|
api := r.Group("/api")
|
||||||
registerAPIRoutes(api, store, cfg.MapTileCacheDir)
|
registerAPIRoutes(api, store, cfg.MapTileCacheDir)
|
||||||
registerAdminRoutes(api.Group("/admin"), store, sessions, mqttStatus, blocking, forwarder, settings, botSender)
|
registerAdminRoutes(api.Group("/admin"), store, sessions, mqttStatus, blocking, forwarder, settings, botSender)
|
||||||
|
|||||||
Reference in New Issue
Block a user