From a638aa9c20350cb8f55910584583e4c8112ca3b9 Mon Sep 17 00:00:00 2001 From: Sarv Date: Sat, 30 Aug 2025 11:32:10 +0800 Subject: [PATCH] fix(conf): tui config write failed (#235) --- internal/chatlog/conf/conf.go | 7 +++++++ internal/chatlog/conf/tui.go | 2 +- internal/chatlog/database/service.go | 1 + internal/chatlog/webhook/webhook.go | 2 +- pkg/config/config.go | 12 +++++++----- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/internal/chatlog/conf/conf.go b/internal/chatlog/conf/conf.go index b268178..65d53d6 100644 --- a/internal/chatlog/conf/conf.go +++ b/internal/chatlog/conf/conf.go @@ -37,6 +37,10 @@ func LoadTUIConfig(configPath string) (*TUIConfig, *config.Manager, error) { return nil, nil, err } conf.ConfigDir = tcm.Path + + b, _ := json.Marshal(conf) + log.Info().Msgf("tui config: %s", string(b)) + return conf, tcm, nil } @@ -85,6 +89,9 @@ func LoadServiceConfig(configPath string, cmdConf map[string]any) (*ServerConfig } } + b, _ := json.Marshal(conf) + log.Info().Msgf("server config: %s", string(b)) + return conf, scm, nil } diff --git a/internal/chatlog/conf/tui.go b/internal/chatlog/conf/tui.go index c18285d..2d54fb4 100644 --- a/internal/chatlog/conf/tui.go +++ b/internal/chatlog/conf/tui.go @@ -1,7 +1,7 @@ package conf type TUIConfig struct { - ConfigDir string `mapstructure:"-"` + ConfigDir string `mapstructure:"-" json:"config_dir"` LastAccount string `mapstructure:"last_account" json:"last_account"` History []ProcessConfig `mapstructure:"history" json:"history"` Webhook *Webhook `mapstructure:"webhook" json:"webhook"` diff --git a/internal/chatlog/database/service.go b/internal/chatlog/database/service.go index 6d0acd9..2a31cd9 100644 --- a/internal/chatlog/database/service.go +++ b/internal/chatlog/database/service.go @@ -116,6 +116,7 @@ func (s *Service) initWebhook() error { s.webhookCancel = cancel hooks := s.webhook.GetHooks(ctx, s.db) for _, hook := range hooks { + log.Info().Msgf("set callback %#v", hook) if err := s.db.SetCallback(hook.Group(), hook.Callback); err != nil { log.Error().Err(err).Msgf("set callback %#v failed", hook) return err diff --git a/internal/chatlog/webhook/webhook.go b/internal/chatlog/webhook/webhook.go index 7c35f72..5e0d725 100644 --- a/internal/chatlog/webhook/webhook.go +++ b/internal/chatlog/webhook/webhook.go @@ -186,7 +186,7 @@ func (m *MessageWebhook) Do(event fsnotify.Event) { req, _ := http.NewRequest("POST", m.conf.URL, bytes.NewBuffer(body)) req.Header.Set("Content-Type", "application/json") - log.Debug().Msgf("post messages to %s, body: %s", m.conf.URL, string(body)) + log.Info().Msgf("post messages to %s, body: %s", m.conf.URL, string(body)) resp, err := m.client.Do(req) if err != nil { log.Error().Err(err).Msgf("post messages failed") diff --git a/pkg/config/config.go b/pkg/config/config.go index cc19c06..e79244c 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -83,11 +83,12 @@ func New(app, path, name, envPrefix string, writeConfig bool) (*Manager, error) } return &Manager{ - App: app, - EnvPrefix: envPrefix, - Path: path, - Name: name, - Viper: v, + App: app, + EnvPrefix: envPrefix, + Path: path, + Name: name, + Viper: v, + WriteConfig: writeConfig, }, nil } @@ -95,6 +96,7 @@ func New(app, path, name, envPrefix string, writeConfig bool) (*Manager, error) // It unmarshals the configuration into the provided conf interface. func (c *Manager) Load(conf interface{}) error { if err := c.Viper.ReadInConfig(); err != nil { + log.Error().Err(err).Msg("read config failed") if c.WriteConfig { if err := c.Viper.SafeWriteConfig(); err != nil { return err