diff --git a/backend/server/api/workerpool.go b/backend/server/api/workerpool.go index 64cdaf6..3082973 100644 --- a/backend/server/api/workerpool.go +++ b/backend/server/api/workerpool.go @@ -5,7 +5,7 @@ import ( "net/http" "os/exec" - Mailer "github.com/baato/before-after/mailer" + "github.com/baato/before-after/services" "github.com/gin-gonic/gin" ) @@ -75,9 +75,9 @@ func (w Worker) start() { // Dispatcher has added a job to my jobQueue. var jobstatus JobStatus = provision(job.Year, job.Bbox, job.Style, job.Name, job.Uuid, job.Country, job.Continent, job.FullName, job.Email) if jobstatus.status == "done" { - Mailer.SendSuccessMail(job.Email, job.FullName, job.Uuid, job.Name) + services.SendSuccessMail(job.Email, job.FullName, job.Uuid, job.Name) } else if jobstatus.status == "error" { - Mailer.SendErrorMail(job.Email, job.FullName, job.Uuid, jobstatus.err, job.Year, job.Bbox, job.Name, job.Country, job.Continent, job.Email) + services.SendErrorMail(job.Email, job.FullName, job.Uuid, jobstatus.err, job.Year, job.Bbox, job.Name, job.Country, job.Continent, job.Email) } case <-w.quitChan: diff --git a/backend/server/mailer/email-template.html b/backend/server/services/email_templates/email-template.html similarity index 100% rename from backend/server/mailer/email-template.html rename to backend/server/services/email_templates/email-template.html diff --git a/backend/server/mailer/error-email-template.html b/backend/server/services/email_templates/error-email-template.html similarity index 100% rename from backend/server/mailer/error-email-template.html rename to backend/server/services/email_templates/error-email-template.html diff --git a/backend/server/mailer/index.html b/backend/server/services/email_templates/index.html similarity index 100% rename from backend/server/mailer/index.html rename to backend/server/services/email_templates/index.html diff --git a/backend/server/mailer/mailer.go b/backend/server/services/mailer.go similarity index 82% rename from backend/server/mailer/mailer.go rename to backend/server/services/mailer.go index 916da6f..acfc6a5 100644 --- a/backend/server/mailer/mailer.go +++ b/backend/server/services/mailer.go @@ -1,4 +1,4 @@ -package mailer +package services import ( "bytes" @@ -7,22 +7,8 @@ import ( "net/smtp" "os" "text/template" - - "github.com/baato/before-after/util" -) - -var ( - config util.Config - configErr error ) -func init() { - config, configErr = util.LoadConfig("../../") - if configErr != nil { - log.Fatal("cannot load config:", configErr) - } -} - func sendMail(receiver []string, body bytes.Buffer) { var smtpAuth = smtp.PlainAuth("", config.SMTPUsername, config.SMTPPassword, config.SMTPHost) var smtpURL = config.SMTPHost + ":" + config.SMTPPort @@ -36,7 +22,7 @@ func SendSuccessMail(receiver string, FullName string, Uuid string, Name string) if err != nil { log.Fatal(err) } - t, err := template.ParseFiles(wd + "/mailer/email-template.html") + t, err := template.ParseFiles(wd + "/services/email_templates/email-template.html") if err != nil { fmt.Println(err) } @@ -63,7 +49,7 @@ func SendErrorMail(receiver string, FullName, Uuid, ErrorAt, Year, Bbox, Name, C if err != nil { log.Fatal(err) } - t, err := template.ParseFiles(wd + "/mailer/error-email-template.html") + t, err := template.ParseFiles(wd + "/services/email_templates/error-email-template.html") if err != nil { fmt.Println(err) }