diff --git a/install.sh b/install.sh index 2edb0d8..c2911cf 100644 --- a/install.sh +++ b/install.sh @@ -79,6 +79,7 @@ web: port: 8080 socket_path: ${SOCKET_PATH} static_dir: ${INSTALL_DIR}/dist + console_log: true admin: username: admin password: admin diff --git a/internal/config/config.go b/internal/config/config.go index e13df42..c0e6027 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -66,6 +66,7 @@ type WebConfig struct { SocketPath string `yaml:"socket_path"` StaticDir string `yaml:"static_dir"` MapTileCacheDir string `yaml:"map_tile_cache_dir"` + ConsoleLog bool `yaml:"console_log"` Admin WebAdminConfig `yaml:"admin"` } @@ -132,6 +133,7 @@ type rawWebConfig struct { SocketPath *string `yaml:"socket_path"` StaticDir *string `yaml:"static_dir"` MapTileCacheDir *string `yaml:"map_tile_cache_dir"` + ConsoleLog *bool `yaml:"console_log"` Admin *rawWebAdminConfig `yaml:"admin"` } @@ -171,6 +173,7 @@ func Default() *Config { SocketPath: defaultWebSocketPath(), StaticDir: "./dist", MapTileCacheDir: defaultMapTileCacheDir(), + ConsoleLog: true, Admin: WebAdminConfig{ Username: "admin", Password: "admin", @@ -264,9 +267,9 @@ func defaultDataDir() string { func defaultDataDirForGOOS(goos string) string { 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 加载配置文件;文件不存在时生成,字段缺失时自动补全并写回。 @@ -428,6 +431,11 @@ func normalize(raw rawConfig) (*Config, bool) { } else { 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 { changed = true } else { diff --git a/internal/web/web.go b/internal/web/web.go index 50272ea..6a6a8fa 100644 --- a/internal/web/web.go +++ b/internal/web/web.go @@ -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 { r := gin.New() - r.Use(gin.Logger(), gin.Recovery()) + if cfg.ConsoleLog { + r.Use(gin.Logger(), gin.Recovery()) + } else { + r.Use(gin.Recovery()) + } api := r.Group("/api") registerAPIRoutes(api, store, cfg.MapTileCacheDir) registerAdminRoutes(api.Group("/admin"), store, sessions, mqttStatus, blocking, forwarder, settings, botSender)