99 lines
1.9 KiB
Go
99 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"email-notification/app"
|
|
"email-notification/config"
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/joho/godotenv"
|
|
)
|
|
|
|
func main() {
|
|
fmt.Println("Test")
|
|
err := godotenv.Load()
|
|
if err != nil {
|
|
log.Fatal("Error loading .env file")
|
|
}
|
|
|
|
config.NewDatabase()
|
|
|
|
to := []string{"teddy.nutech@gmail.com"}
|
|
cc := []string{"teddy.nutech@gmail.com"}
|
|
subject := "test"
|
|
message := "test"
|
|
|
|
// conn, err := amqp091.Dial("amqp://guest:guest@36.66.3.44:7012/")
|
|
// if err != nil {
|
|
// fmt.Println("Failed to connect to RabbitMQ: ", err)
|
|
// }
|
|
// defer conn.Close()
|
|
|
|
// ch, err := conn.Channel()
|
|
// if err != nil {
|
|
// fmt.Println("Failed to open a channel: ", err)
|
|
// }
|
|
// defer ch.Close()
|
|
|
|
http.HandleFunc("/notif-email", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
// ch.Publish("notification", "email", false, false, amqp091.Publishing{
|
|
// ContentType: "application/json",
|
|
// Body: []byte("test-email"),
|
|
// })
|
|
|
|
go func() {
|
|
fmt.Println("sending email...")
|
|
err := app.SendEmail(to, cc, subject, message)
|
|
if err != nil {
|
|
fmt.Println("error", err.Error())
|
|
}
|
|
fmt.Println("email sent")
|
|
}()
|
|
|
|
w.Write([]byte{})
|
|
})
|
|
|
|
port := os.Getenv("PORT")
|
|
|
|
http.ListenAndServe(":"+port, nil)
|
|
|
|
// q, err := ch.QueueDeclare(
|
|
// "email", // name
|
|
// false,
|
|
// false,
|
|
// false,
|
|
// false,
|
|
// nil,
|
|
// )
|
|
// if err != nil {
|
|
// fmt.Println("Failed to declare a queue:", err)
|
|
// }
|
|
|
|
// msgs, err := ch.Consume(
|
|
// "email",
|
|
// "", // consumer
|
|
// true, // auto-ack
|
|
// false, // exclusive
|
|
// false, // no-local
|
|
// false, // no-wait
|
|
// nil,
|
|
// )
|
|
// if err != nil {
|
|
// fmt.Println("Failed to register a consumer: ", err)
|
|
// }
|
|
|
|
// forever := make(chan bool)
|
|
|
|
// go func() {
|
|
// for d := range msgs {
|
|
// log.Printf("Received a message: %s", d.Body)
|
|
// }
|
|
// }()
|
|
|
|
// fmt.Println(" [*] Waiting for messages. To exit press CTRL+C")
|
|
// <-forever
|
|
}
|