slaventius 2 years ago
parent 4b9e7fc845
commit f31adc2bb2
  1. 4
      .vscode/launch.json
  2. 36
      internal/authPostman.go
  3. 26
      internal/config/config.go

@ -14,8 +14,8 @@
"SMTP_HOST":"smtp.mail.ru", "SMTP_HOST":"smtp.mail.ru",
// "SMTP_PORT":"465", // "SMTP_PORT":"465",
"SMTP_PORT":"587", "SMTP_PORT":"587",
"SMTP_SENDER":"test3kbot@mail.ru", "SMTP_SENDER":"test3kbotan@mail.ru",
"SMTP_PASSWORD":"hwNhMgPyBzMjwCj3hFPp", "SMTP_PASSWORD":"vSJYfUbpamiUFkKx1DJA",
"KAFKA_PORT":"9092", "KAFKA_PORT":"9092",
"KAFKA_HOST":"37.143.12.169", "KAFKA_HOST":"37.143.12.169",
"CHAT_ID":"150697696", "CHAT_ID":"150697696",

@ -10,7 +10,9 @@ import (
"git.slaventius.ru/test3k/authPostman/internal/config" "git.slaventius.ru/test3k/authPostman/internal/config"
kafka "git.slaventius.ru/test3k/authPostman/internal/transport/kafka" kafka "git.slaventius.ru/test3k/authPostman/internal/transport/kafka"
"git.slaventius.ru/test3k/authPostman/internal/transport/telegram"
// telegram "git.slaventius.ru/test3k/authPostman/internal/transport/telegram"
smtp "git.slaventius.ru/test3k/authPostman/internal/transport/smtp"
) )
const ( const (
@ -65,26 +67,26 @@ func (s *AuthPostmanServer) ReadMessage(offset int64) error {
// //
text := fmt.Sprintf("Confirmation code %v", amsg.Code) text := fmt.Sprintf("Confirmation code %v", amsg.Code)
postman := telegram.NewService(s.config.Telegram.ChatToken) // postman := telegram.NewService(s.config.Telegram.ChatToken)
message := postman.NewMessage(s.config.Telegram.ChatID, text) // message := postman.NewMessage(s.config.Telegram.ChatID, text)
ers := postman.SendMessage(message) // ers := postman.SendMessage(message)
if ers != nil {
log.Print(ers)
} else {
log.Printf("send code %s to %s completed", amsg.Code, amsg.Email)
}
// //
// message := smtp.NewMessage("Confirmation code", text)
// message.AppendRecipient(amsg.Email)
// //
// smtpSender := smtp.NewService(s.config.Smtp.Host, s.config.Smtp.Port, s.config.Smtp.Sender, s.config.Smtp.Password)
// ers := smtpSender.Send(message)
// if ers != nil { // if ers != nil {
// log.Print(ers) // log.Print(ers)
// } else { // } else {
// log.Printf("send code %s to %s completed", amsg.Code, amsg.Email) // log.Printf("send code %s to %s completed", amsg.Code, amsg.Email)
// } // }
//
message := smtp.NewMessage("Confirmation code", text)
message.AppendRecipient(amsg.Email)
//
smtpSender := smtp.NewService(s.config.Smtp.Host, s.config.Smtp.Port, s.config.Smtp.Sender, s.config.Smtp.Password)
ers := smtpSender.Send(message)
if ers != nil {
log.Print(ers)
} else {
log.Printf("send code %s to %s completed", amsg.Code, amsg.Email)
}
} }
} }

@ -6,18 +6,18 @@ import (
"github.com/kelseyhightower/envconfig" "github.com/kelseyhightower/envconfig"
) )
// type smtpConfig struct { type smtpConfig struct {
// Port int `envconfig:"SMTP_PORT"` Port int `envconfig:"SMTP_PORT"`
// Host string `envconfig:"SMTP_HOST"` Host string `envconfig:"SMTP_HOST"`
// Sender string `envconfig:"SMTP_SENDER"` Sender string `envconfig:"SMTP_SENDER"`
// Password string `envconfig:"SMTP_PASSWORD"` Password string `envconfig:"SMTP_PASSWORD"`
// }
type telegramConfig struct {
ChatID int64 `envconfig:"CHAT_ID"`
ChatToken string `envconfig:"CHAT_TOKEN"`
} }
// type telegramConfig struct {
// ChatID int64 `envconfig:"CHAT_ID"`
// ChatToken string `envconfig:"CHAT_TOKEN"`
// }
type kafkaConfig struct { type kafkaConfig struct {
Port int `envconfig:"KAFKA_PORT"` Port int `envconfig:"KAFKA_PORT"`
Host string `envconfig:"KAFKA_HOST"` Host string `envconfig:"KAFKA_HOST"`
@ -25,9 +25,9 @@ type kafkaConfig struct {
// ... // ...
type Config struct { type Config struct {
// Smtp smtpConfig Smtp smtpConfig
Kafka kafkaConfig Kafka kafkaConfig
Telegram telegramConfig // Telegram telegramConfig
} }
func NewConfig() *Config { func NewConfig() *Config {

Loading…
Cancel
Save