Skip to content

Commit

Permalink
Refactor {{ UnsubURL }} into a global function (breaking change)
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Feb 9, 2020
1 parent 2ee2e68 commit 62aa31b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
24 changes: 12 additions & 12 deletions main.go
Expand Up @@ -30,16 +30,16 @@ import (
)

type constants struct {
RootURL string `koanf:"root"`
LogoURL string `koanf:"logo_url"`
FaviconURL string `koanf:"favicon_url"`
UnsubscribeURL string
LinkTrackURL string
ViewTrackURL string
OptinURL string
FromEmail string `koanf:"from_email"`
NotifyEmails []string `koanf:"notify_emails"`
Privacy privacyOptions `koanf:"privacy"`
RootURL string `koanf:"root"`
LogoURL string `koanf:"logo_url"`
FaviconURL string `koanf:"favicon_url"`
UnsubURL string
LinkTrackURL string
ViewTrackURL string
OptinURL string
FromEmail string `koanf:"from_email"`
NotifyEmails []string `koanf:"notify_emails"`
Privacy privacyOptions `koanf:"privacy"`
}

type privacyOptions struct {
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down
12 changes: 7 additions & 5 deletions manager/manager.go
Expand Up @@ -63,8 +63,9 @@ type Message struct {
Subscriber *models.Subscriber
Body []byte

from string
to string
from string
to string
unsubURL string
}

// Config has parameters for configuring the manager.
Expand Down Expand Up @@ -108,8 +109,9 @@ func (m *Manager) NewMessage(c *models.Campaign, s *models.Subscriber) *Message
Campaign: c,
Subscriber: s,

from: c.FromEmail,
to: s.Email,
from: c.FromEmail,
to: s.Email,
unsubURL: fmt.Sprintf(m.cfg.UnsubURL, c.UUID, s.UUID),
}
}

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 62aa31b

Please sign in to comment.