fix(conf): tui config write failed (#235)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user