Skip to content

Commit

Permalink
code(pkg/notifier) - imrpove console
Browse files Browse the repository at this point in the history
  • Loading branch information
PxyUp committed Jan 31, 2024
1 parent 0b53834 commit d4fe27b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ type HttpConfig struct {
Timeout uint32 `yaml:"timeout" json:"timeout"`
}

type ConsoleConfig struct{}
type ConsoleConfig struct {
OnlyResult bool `json:"only_result" yaml:"only_result"`
}

type RedisNotifierConfig struct {
Addr string `json:"addr" yaml:"addr"`
Expand Down
9 changes: 9 additions & 0 deletions pkg/notifier/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ type console struct {
}

func (o *console) notify(record *singleRecord) error {
if o.cfg.OnlyResult {
_, errOut := fmt.Fprintln(os.Stdout, string(record.Body))
if errOut != nil {
o.logger.Errorw("cant send to stdout", "error", errOut.Error())
return errOut
}
return nil
}

bb, err := json.Marshal(record)
if err != nil {
o.logger.Errorw("cant unmarshal record", "error", err.Error())
Expand Down
2 changes: 1 addition & 1 deletion pkg/notifier/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var (
_ Notifier = &telegramBot{}
)

func NewTelegramBot(name string, generalCfg *config.NotifierConfig, cfg *config.TelegramBotConfig) (*telegramBot, error) {
func NewTelegramBot(name string, cfg *config.TelegramBotConfig) (*telegramBot, error) {
botApi, err := tgbotapi.NewBotAPI(utils.Format(cfg.Token, nil, nil))
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func CreateProcessor(item *config.Item, refMap config.RefMap, logger logger.Logg

if item.NotifierConfig != nil {
if item.NotifierConfig.TelegramBot != nil {
tgBot, errBot := notifier.NewTelegramBot(item.Name, item.NotifierConfig, item.NotifierConfig.TelegramBot)
tgBot, errBot := notifier.NewTelegramBot(item.Name, item.NotifierConfig.TelegramBot)
if errBot != nil {
logger.Infow("cant setup telegram bot notifier", "error", errBot.Error())
} else {
Expand Down

0 comments on commit d4fe27b

Please sign in to comment.