Skip to content

Commit a638aa9

Browse files
authored
fix(conf): tui config write failed (#235)
1 parent 08323e0 commit a638aa9

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

internal/chatlog/conf/conf.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ func LoadTUIConfig(configPath string) (*TUIConfig, *config.Manager, error) {
3737
return nil, nil, err
3838
}
3939
conf.ConfigDir = tcm.Path
40+
41+
b, _ := json.Marshal(conf)
42+
log.Info().Msgf("tui config: %s", string(b))
43+
4044
return conf, tcm, nil
4145
}
4246

@@ -85,6 +89,9 @@ func LoadServiceConfig(configPath string, cmdConf map[string]any) (*ServerConfig
8589
}
8690
}
8791

92+
b, _ := json.Marshal(conf)
93+
log.Info().Msgf("server config: %s", string(b))
94+
8895
return conf, scm, nil
8996
}
9097

internal/chatlog/conf/tui.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package conf
22

33
type TUIConfig struct {
4-
ConfigDir string `mapstructure:"-"`
4+
ConfigDir string `mapstructure:"-" json:"config_dir"`
55
LastAccount string `mapstructure:"last_account" json:"last_account"`
66
History []ProcessConfig `mapstructure:"history" json:"history"`
77
Webhook *Webhook `mapstructure:"webhook" json:"webhook"`

internal/chatlog/database/service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ func (s *Service) initWebhook() error {
116116
s.webhookCancel = cancel
117117
hooks := s.webhook.GetHooks(ctx, s.db)
118118
for _, hook := range hooks {
119+
log.Info().Msgf("set callback %#v", hook)
119120
if err := s.db.SetCallback(hook.Group(), hook.Callback); err != nil {
120121
log.Error().Err(err).Msgf("set callback %#v failed", hook)
121122
return err

internal/chatlog/webhook/webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func (m *MessageWebhook) Do(event fsnotify.Event) {
186186
req, _ := http.NewRequest("POST", m.conf.URL, bytes.NewBuffer(body))
187187
req.Header.Set("Content-Type", "application/json")
188188

189-
log.Debug().Msgf("post messages to %s, body: %s", m.conf.URL, string(body))
189+
log.Info().Msgf("post messages to %s, body: %s", m.conf.URL, string(body))
190190
resp, err := m.client.Do(req)
191191
if err != nil {
192192
log.Error().Err(err).Msgf("post messages failed")

pkg/config/config.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,20 @@ func New(app, path, name, envPrefix string, writeConfig bool) (*Manager, error)
8383
}
8484

8585
return &Manager{
86-
App: app,
87-
EnvPrefix: envPrefix,
88-
Path: path,
89-
Name: name,
90-
Viper: v,
86+
App: app,
87+
EnvPrefix: envPrefix,
88+
Path: path,
89+
Name: name,
90+
Viper: v,
91+
WriteConfig: writeConfig,
9192
}, nil
9293
}
9394

9495
// Load loads the configuration from the previously initialized file.
9596
// It unmarshals the configuration into the provided conf interface.
9697
func (c *Manager) Load(conf interface{}) error {
9798
if err := c.Viper.ReadInConfig(); err != nil {
99+
log.Error().Err(err).Msg("read config failed")
98100
if c.WriteConfig {
99101
if err := c.Viper.SafeWriteConfig(); err != nil {
100102
return err

0 commit comments

Comments
 (0)