Skip to content

Commit

Permalink
Cleanup unnecessary pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Mar 8, 2020
1 parent ac2145d commit 5f6a4af
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions campaigns.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func handlePreviewCampaign(c echo.Context) error {
}

// Render the message body.
m := app.manager.NewMessage(camp, &sub)
m := app.manager.NewMessage(camp, sub)
if err := m.Render(); err != nil {
app.log.Printf("error rendering message: %v", err)
return echo.NewHTTPError(http.StatusBadRequest,
Expand Down Expand Up @@ -538,7 +538,7 @@ func handleTestCampaign(c echo.Context) error {
// Send the test messages.
for _, s := range subs {
sub := s
if err := sendTestMessage(&sub, &camp, app); err != nil {
if err := sendTestMessage(sub, &camp, app); err != nil {
return echo.NewHTTPError(http.StatusBadRequest,
fmt.Sprintf("Error sending test: %v", err))
}
Expand All @@ -548,7 +548,7 @@ func handleTestCampaign(c echo.Context) error {
}

// sendTestMessage takes a campaign and a subsriber and sends out a sample campaign message.
func sendTestMessage(sub *models.Subscriber, camp *models.Campaign, app *App) error {
func sendTestMessage(sub models.Subscriber, camp *models.Campaign, app *App) error {
if err := camp.CompileTemplate(app.manager.TemplateFuncs(camp)); err != nil {
app.log.Printf("error compiling template: %v", err)
return fmt.Errorf("Error compiling template: %v", err)
Expand Down
12 changes: 6 additions & 6 deletions internal/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const (
// that provides subscriber and campaign records.
type DataSource interface {
NextCampaigns(excludeIDs []int64) ([]*models.Campaign, error)
NextSubscribers(campID, limit int) ([]*models.Subscriber, error)
NextSubscribers(campID, limit int) ([]models.Subscriber, error)
GetCampaign(campID int) (*models.Campaign, error)
UpdateCampaignStatus(campID int, status string) error
CreateLink(url string) (string, error)
Expand All @@ -52,15 +52,15 @@ type Manager struct {
linksMutex sync.RWMutex

subFetchQueue chan *models.Campaign
msgQueue chan *Message
msgQueue chan Message
msgErrorQueue chan msgError
msgErrorCounts map[int]int
}

// Message represents an active subscriber that's being processed.
type Message struct {
Campaign *models.Campaign
Subscriber *models.Subscriber
Subscriber models.Subscriber
Body []byte

from string
Expand Down Expand Up @@ -96,16 +96,16 @@ func New(cfg Config, src DataSource, notifCB models.AdminNotifCallback, l *log.L
camps: make(map[int]*models.Campaign),
links: make(map[string]string),
subFetchQueue: make(chan *models.Campaign, cfg.Concurrency),
msgQueue: make(chan *Message, cfg.Concurrency),
msgQueue: make(chan Message, cfg.Concurrency),
msgErrorQueue: make(chan msgError, cfg.MaxSendErrors),
msgErrorCounts: make(map[int]int),
}
}

// NewMessage creates and returns a Message that is made available
// to message templates while they're compiled.
func (m *Manager) NewMessage(c *models.Campaign, s *models.Subscriber) *Message {
return &Message{
func (m *Manager) NewMessage(c *models.Campaign, s models.Subscriber) Message {
return Message{
Campaign: c,
Subscriber: s,

Expand Down
4 changes: 2 additions & 2 deletions manager_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func (r *runnerDB) NextCampaigns(excludeIDs []int64) ([]*models.Campaign, error)
// Since batches are processed sequentially, the retrieval is ordered by ID,
// and every batch takes the last ID of the last batch and fetches the next
// batch above that.
func (r *runnerDB) NextSubscribers(campID, limit int) ([]*models.Subscriber, error) {
var out []*models.Subscriber
func (r *runnerDB) NextSubscribers(campID, limit int) ([]models.Subscriber, error) {
var out []models.Subscriber
err := r.queries.NextCampaignSubscribers.Select(&out, campID, limit)
return out, err
}
Expand Down
2 changes: 1 addition & 1 deletion templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func handlePreviewTemplate(c echo.Context) error {
}

// Render the message body.
m := app.manager.NewMessage(&camp, &dummySubscriber)
m := app.manager.NewMessage(&camp, dummySubscriber)
if err := m.Render(); err != nil {
return echo.NewHTTPError(http.StatusBadRequest,
fmt.Sprintf("Error rendering message: %v", err))
Expand Down

0 comments on commit 5f6a4af

Please sign in to comment.