Refactor {{ UnsubURL }} into a global function (breaking change)

This commit is contained in:
Kailash Nadh 2020-02-09 19:15:14 +05:30
parent 2ee2e68230
commit 62aa31b14c
2 changed files with 19 additions and 17 deletions

View File

@ -33,7 +33,7 @@ type constants struct {
RootURL string `koanf:"root"`
LogoURL string `koanf:"logo_url"`
FaviconURL string `koanf:"favicon_url"`
UnsubscribeURL string
UnsubURL string
LinkTrackURL string
ViewTrackURL string
OptinURL string
@ -309,7 +309,7 @@ func main() {
// Static URLS.
// url.com/subscription/{campaign_uuid}/{subscriber_uuid}
c.UnsubscribeURL = fmt.Sprintf("%s/subscription/%%s/%%s", app.Constants.RootURL)
c.UnsubURL = fmt.Sprintf("%s/subscription/%%s/%%s", app.Constants.RootURL)
// url.com/subscription/optin/{subscriber_uuid}
c.OptinURL = fmt.Sprintf("%s/subscription/optin/%%s?%%s", app.Constants.RootURL)
@ -328,7 +328,7 @@ func main() {
Concurrency: ko.Int("app.concurrency"),
MaxSendErrors: ko.Int("app.max_send_errors"),
FromEmail: app.Constants.FromEmail,
UnsubURL: c.UnsubscribeURL,
UnsubURL: c.UnsubURL,
OptinURL: c.OptinURL,
LinkTrackURL: c.LinkTrackURL,
ViewTrackURL: c.ViewTrackURL,

View File

@ -65,6 +65,7 @@ type Message struct {
from string
to string
unsubURL string
}
// Config has parameters for configuring the manager.
@ -110,6 +111,7 @@ func (m *Manager) NewMessage(c *models.Campaign, s *models.Subscriber) *Message
from: c.FromEmail,
to: s.Email,
unsubURL: fmt.Sprintf(m.cfg.UnsubURL, c.UUID, s.UUID),
}
}
@ -422,7 +424,7 @@ func (m *Manager) TemplateFuncs(c *models.Campaign) template.FuncMap {
fmt.Sprintf(m.cfg.ViewTrackURL, msg.Campaign.UUID, msg.Subscriber.UUID)))
},
"UnsubscribeURL": func(msg *Message) string {
return fmt.Sprintf(m.cfg.UnsubURL, c.UUID, msg.Subscriber.UUID)
return msg.unsubURL
},
"OptinURL": func(msg *Message) string {
// Add list IDs.