Moved mail to services package.
This commit is contained in:
parent
af645ee2e4
commit
28bda89863
27
mail/mail.go
27
mail/mail.go
@ -1,27 +0,0 @@
|
||||
package mail
|
||||
|
||||
import (
|
||||
"goweb/config"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
config *config.Config
|
||||
}
|
||||
|
||||
func NewClient(cfg *config.Config) (*Client, error) {
|
||||
return &Client{
|
||||
config: cfg,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *Client) Send(ctx echo.Context, to, body string) error {
|
||||
if c.config.App.Environment != config.EnvProduction {
|
||||
// IE, skip sending email..
|
||||
}
|
||||
ctx.Logger().Debugf("Mock email sent. To: %s Body: %s", to, body)
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO: Send with template?
|
50
services/mail.go
Normal file
50
services/mail.go
Normal file
@ -0,0 +1,50 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"goweb/config"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
// MailClient provides a client for sending email
|
||||
// This is purposely not completed because there are many different methods and services
|
||||
// for sending email, many of which are very different. Choose what works best for you
|
||||
// and populate the methods below
|
||||
type MailClient struct {
|
||||
// config stores application configuration
|
||||
config *config.Config
|
||||
}
|
||||
|
||||
// NewMailClient creates a new MailClient
|
||||
func NewMailClient(cfg *config.Config) (*MailClient, error) {
|
||||
return &MailClient{
|
||||
config: cfg,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Send sends an email to a given email address with a given body
|
||||
func (c *MailClient) Send(ctx echo.Context, to, body string) error {
|
||||
if c.skipSend() {
|
||||
ctx.Logger().Debugf("skipping email sent to: %s")
|
||||
}
|
||||
|
||||
// TODO: Finish based on your mail sender of choice
|
||||
return nil
|
||||
}
|
||||
|
||||
// SendTemplate sends an email to a given email address using a template and data which is passed to the template
|
||||
// The template name should only include the filename without the extension or directory.
|
||||
// The funcmap will be automatically added to the template and the data will be passed in.
|
||||
func (c *MailClient) SendTemplate(ctx echo.Context, to, template string, data interface{}) error {
|
||||
if c.skipSend() {
|
||||
ctx.Logger().Debugf("skipping template email sent to: %s")
|
||||
}
|
||||
|
||||
// TODO: Finish based on your mail sender of choice
|
||||
return nil
|
||||
}
|
||||
|
||||
// skipSend determines if mail sending should be skipped
|
||||
func (c *MailClient) skipSend() bool {
|
||||
return c.config.App.Environment != config.EnvProduction
|
||||
}
|
3
services/mail_test.go
Normal file
3
services/mail_test.go
Normal file
@ -0,0 +1,3 @@
|
||||
package services
|
||||
|
||||
// Fill this in once you implement your mail client
|
Loading…
Reference in New Issue
Block a user