Documentation ¶
Overview ¶
package core is the collection of re-usable functions that primarily provides data (DB / CRUD) operations to the app. For instance, creating and mutating objects like lists, subscribers etc. All such methods return an echo.HTTPError{} (which implements error.error) that can be directly returned as a response to HTTP handlers without further processing.
Index ¶
- Constants
- type Constants
- type Core
- func (c *Core) AddSubscriptions(subIDs, listIDs []int, status string) error
- func (c *Core) AddSubscriptionsByQuery(query string, sourceListIDs, targetListIDs []int, status string) error
- func (c *Core) BlocklistSubscribers(subIDs []int) error
- func (c *Core) BlocklistSubscribersByQuery(query string, listIDs []int) error
- func (c *Core) ConfirmOptionSubscription(subUUID string, listUUIDs []string, meta models.JSON) error
- func (c *Core) CreateCampaign(o models.Campaign, listIDs []int, mediaIDs []int) (models.Campaign, error)
- func (c *Core) CreateList(l models.List) (models.List, error)
- func (c *Core) CreateTemplate(name, typ, subject string, body []byte) (models.Template, error)
- func (c *Core) DeleteBlocklistedSubscribers() (int, error)
- func (c *Core) DeleteBounce(id int) error
- func (c *Core) DeleteBounces(ids []int) error
- func (c *Core) DeleteCampaign(id int) error
- func (c *Core) DeleteCampaignLinkClicks(before time.Time) error
- func (c *Core) DeleteCampaignViews(before time.Time) error
- func (c *Core) DeleteList(id int) error
- func (c *Core) DeleteLists(ids []int) error
- func (c *Core) DeleteMedia(id int) (string, error)
- func (c *Core) DeleteOrphanSubscribers() (int, error)
- func (c *Core) DeleteSubscriberBounces(id int, uuid string) error
- func (c *Core) DeleteSubscribers(subIDs []int, subUUIDs []string) error
- func (c *Core) DeleteSubscribersByQuery(query string, listIDs []int) error
- func (c *Core) DeleteSubscriptions(subIDs, listIDs []int) error
- func (c *Core) DeleteSubscriptionsByQuery(query string, sourceListIDs, targetListIDs []int) error
- func (c *Core) DeleteTemplate(id int) error
- func (c *Core) DeleteUnconfirmedSubscriptions(beforeDate time.Time) (int, error)
- func (c *Core) ExportSubscribers(query string, subIDs, listIDs []int, batchSize int) (func() ([]models.SubscriberExport, error), error)
- func (c *Core) GetArchivedCampaign(id int, uuid, archiveSlug string) (models.Campaign, error)
- func (c *Core) GetArchivedCampaigns(offset, limit int) (models.Campaigns, int, error)
- func (c *Core) GetBounce(id int) (models.Bounce, error)
- func (c *Core) GetCampaign(id int, uuid, archiveSlug string) (models.Campaign, error)
- func (c *Core) GetCampaignAnalyticsCounts(campIDs []int, typ, fromDate, toDate string) ([]models.CampaignAnalyticsCount, error)
- func (c *Core) GetCampaignAnalyticsLinks(campIDs []int, typ, fromDate, toDate string) ([]models.CampaignAnalyticsLink, error)
- func (c *Core) GetCampaignForPreview(id, tplID int) (models.Campaign, error)
- func (c *Core) GetDashboardCharts() (types.JSONText, error)
- func (c *Core) GetDashboardCounts() (types.JSONText, error)
- func (c *Core) GetList(id int, uuid string) (models.List, error)
- func (c *Core) GetLists(typ string) ([]models.List, error)
- func (c *Core) GetListsByOptin(ids []int, optinType string) ([]models.List, error)
- func (c *Core) GetMedia(id int, uuid string, s media.Store) (media.Media, error)
- func (c *Core) GetRunningCampaignStats() ([]models.CampaignStats, error)
- func (c *Core) GetSettings() (models.Settings, error)
- func (c *Core) GetSubscriber(id int, uuid, email string) (models.Subscriber, error)
- func (c *Core) GetSubscriberLists(subID int, uuid string, listIDs []int, listUUIDs []string, subStatus string, ...) ([]models.List, error)
- func (c *Core) GetSubscriberProfileForExport(id int, uuid string) (models.SubscriberExportProfile, error)
- func (c *Core) GetSubscribersByEmail(emails []string) (models.Subscribers, error)
- func (c *Core) GetSubscriptions(subID int, subUUID string, allLists bool) ([]models.Subscription, error)
- func (c *Core) GetTemplate(id int, noBody bool) (models.Template, error)
- func (c *Core) GetTemplates(status string, noBody bool) ([]models.Template, error)
- func (c *Core) InsertMedia(fileName, thumbName, contentType string, meta models.JSON, provider string, ...) (media.Media, error)
- func (c *Core) InsertSubscriber(sub models.Subscriber, listIDs []int, listUUIDs []string, preconfirm bool) (models.Subscriber, bool, error)
- func (c *Core) QueryBounces(campID, subID int, source, orderBy, order string, offset, limit int) ([]models.Bounce, int, error)
- func (c *Core) QueryCampaigns(searchStr string, statuses, tags []string, orderBy, order string, ...) (models.Campaigns, int, error)
- func (c *Core) QueryLists(searchStr, typ, optin string, tags []string, orderBy, order string, ...) ([]models.List, int, error)
- func (c *Core) QueryMedia(provider string, s media.Store, query string, offset, limit int) ([]media.Media, int, error)
- func (c *Core) QuerySubscribers(query string, listIDs []int, subStatus string, order, orderBy string, ...) (models.Subscribers, int, error)
- func (c *Core) RecordBounce(b models.Bounce) error
- func (c *Core) RefreshMatView(name string, concurrent bool) error
- func (c *Core) RefreshMatViews(concurrent bool) error
- func (c *Core) RegisterCampaignLinkClick(linkUUID, campUUID, subUUID string) (string, error)
- func (c *Core) RegisterCampaignView(campUUID, subUUID string) error
- func (c *Core) SetDefaultTemplate(id int) error
- func (c *Core) UnsubscribeByCampaign(subUUID, campUUID string, blocklist bool) error
- func (c *Core) UnsubscribeLists(subIDs, listIDs []int, listUUIDs []string) error
- func (c *Core) UnsubscribeListsByQuery(query string, sourceListIDs, targetListIDs []int) error
- func (c *Core) UpdateCampaign(id int, o models.Campaign, listIDs []int, mediaIDs []int, sendLater bool) (models.Campaign, error)
- func (c *Core) UpdateCampaignArchive(id int, enabled bool, tplID int, meta models.JSON, archiveSlug string) error
- func (c *Core) UpdateCampaignStatus(id int, status string) (models.Campaign, error)
- func (c *Core) UpdateList(id int, l models.List) (models.List, error)
- func (c *Core) UpdateSettings(s models.Settings) error
- func (c *Core) UpdateSubscriber(id int, sub models.Subscriber) (models.Subscriber, error)
- func (c *Core) UpdateSubscriberWithLists(id int, sub models.Subscriber, listIDs []int, listUUIDs []string, ...) (models.Subscriber, bool, error)
- func (c *Core) UpdateTemplate(id int, name, subject string, body []byte) (models.Template, error)
- type Hooks
- type Opt
Constants ¶
const ( CampaignAnalyticsViews = "views" CampaignAnalyticsClicks = "clicks" CampaignAnalyticsBounces = "bounces" )
const ( SortAsc = "asc" SortDesc = "desc" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Constants ¶
type Constants struct { SendOptinConfirmation bool BounceActions map[string]struct { Count int Action string } CacheSlowQueries bool }
Constants represents constant config.
type Core ¶
type Core struct {
// contains filtered or unexported fields
}
Core represents the listmonk core with all shared, global functions.
func (*Core) AddSubscriptions ¶
AddSubscriptions adds list subscriptions to subscribers.
func (*Core) AddSubscriptionsByQuery ¶
func (c *Core) AddSubscriptionsByQuery(query string, sourceListIDs, targetListIDs []int, status string) error
AddSubscriptionsByQuery adds list subscriptions to subscribers by a given arbitrary query expression. sourceListIDs is the list of list IDs to filter the subscriber query with.
func (*Core) BlocklistSubscribers ¶
BlocklistSubscribers blocklists the given list of subscribers.
func (*Core) BlocklistSubscribersByQuery ¶
BlocklistSubscribersByQuery blocklists the given list of subscribers.
func (*Core) ConfirmOptionSubscription ¶
func (c *Core) ConfirmOptionSubscription(subUUID string, listUUIDs []string, meta models.JSON) error
ConfirmOptionSubscription confirms a subscriber's optin subscription.
func (*Core) CreateCampaign ¶
func (c *Core) CreateCampaign(o models.Campaign, listIDs []int, mediaIDs []int) (models.Campaign, error)
CreateCampaign creates a new campaign.
func (*Core) CreateList ¶
CreateList creates a new list.
func (*Core) CreateTemplate ¶
CreateTemplate creates a new template.
func (*Core) DeleteBlocklistedSubscribers ¶
DeleteBlocklistedSubscribers deletes blocklisted subscribers.
func (*Core) DeleteBounces ¶
DeleteBounces deletes multiple lists.
func (*Core) DeleteCampaign ¶
DeleteCampaign deletes a campaign.
func (*Core) DeleteCampaignLinkClicks ¶
DeleteCampaignLinkClicks deletes campaign views older than a given date.
func (*Core) DeleteCampaignViews ¶
DeleteCampaignViews deletes campaign views older than a given date.
func (*Core) DeleteLists ¶
DeleteLists deletes multiple lists.
func (*Core) DeleteMedia ¶
DeleteMedia deletes a given media item and returns the filename of the deleted item.
func (*Core) DeleteOrphanSubscribers ¶
DeleteOrphanSubscribers deletes orphan subscriber records (subscribers without lists).
func (*Core) DeleteSubscriberBounces ¶
DeleteSubscriberBounces deletes the given list of subscribers.
func (*Core) DeleteSubscribers ¶
DeleteSubscribers deletes the given list of subscribers.
func (*Core) DeleteSubscribersByQuery ¶
DeleteSubscribersByQuery deletes subscribers by a given arbitrary query expression.
func (*Core) DeleteSubscriptions ¶
DeleteSubscriptions delete list subscriptions from subscribers.
func (*Core) DeleteSubscriptionsByQuery ¶
DeleteSubscriptionsByQuery deletes list subscriptions from subscribers by a given arbitrary query expression. sourceListIDs is the list of list IDs to filter the subscriber query with.
func (*Core) DeleteTemplate ¶
DeleteTemplate deletes a given template.
func (*Core) DeleteUnconfirmedSubscriptions ¶
DeleteUnconfirmedSubscriptions sets list subscriptions to 'unsubscribed' by a given arbitrary query expression. sourceListIDs is the list of list IDs to filter the subscriber query with.
func (*Core) ExportSubscribers ¶
func (c *Core) ExportSubscribers(query string, subIDs, listIDs []int, batchSize int) (func() ([]models.SubscriberExport, error), error)
ExportSubscribers returns an iterator function that provides lists of subscribers based on the given criteria in an exportable form. The iterator function returned can be called repeatedly until there are nil subscribers. It's an iterator because exports can be extremely large and may have to be fetched in batches from the DB and streamed somewhere.
func (*Core) GetArchivedCampaign ¶
GetArchivedCampaign retrieves a campaign with the archive template body.
func (*Core) GetArchivedCampaigns ¶
GetArchivedCampaigns retrieves campaigns with a template body.
func (*Core) GetCampaign ¶
GetCampaign retrieves a campaign.
func (*Core) GetCampaignAnalyticsCounts ¶
func (*Core) GetCampaignAnalyticsLinks ¶
func (c *Core) GetCampaignAnalyticsLinks(campIDs []int, typ, fromDate, toDate string) ([]models.CampaignAnalyticsLink, error)
GetCampaignAnalyticsLinks returns link click analytics for the given campaign IDs.
func (*Core) GetCampaignForPreview ¶
GetCampaignForPreview retrieves a campaign with a template body.
func (*Core) GetDashboardCharts ¶
GetDashboardCharts returns chart data points to render on the dashboard.
func (*Core) GetDashboardCounts ¶
GetDashboardCounts returns stats counts to show on the dashboard.
func (*Core) GetListsByOptin ¶
GetListsByOptin returns lists by optin type.
func (*Core) GetRunningCampaignStats ¶
func (c *Core) GetRunningCampaignStats() ([]models.CampaignStats, error)
GetRunningCampaignStats returns the progress stats of running campaigns.
func (*Core) GetSettings ¶
GetSettings returns settings from the DB.
func (*Core) GetSubscriber ¶
GetSubscriber fetches a subscriber by one of the given params.
func (*Core) GetSubscriberLists ¶
func (c *Core) GetSubscriberLists(subID int, uuid string, listIDs []int, listUUIDs []string, subStatus string, listType string) ([]models.List, error)
GetSubscriberLists returns a subscriber's lists based on the given conditions.
func (*Core) GetSubscriberProfileForExport ¶
func (c *Core) GetSubscriberProfileForExport(id int, uuid string) (models.SubscriberExportProfile, error)
GetSubscriberProfileForExport returns the subscriber's profile data as a JSON exportable. Get the subscriber's data. A single query that gets the profile, list subscriptions, campaign views, and link clicks. Names of private lists are replaced with "Private list".
func (*Core) GetSubscribersByEmail ¶
func (c *Core) GetSubscribersByEmail(emails []string) (models.Subscribers, error)
GetSubscribersByEmail fetches a subscriber by one of the given params.
func (*Core) GetSubscriptions ¶
func (c *Core) GetSubscriptions(subID int, subUUID string, allLists bool) ([]models.Subscription, error)
GetSubscriptions retrieves the subscriptions for a subscriber.
func (*Core) GetTemplate ¶
GetTemplate retrieves a given template.
func (*Core) GetTemplates ¶
GetTemplates retrieves all templates.
func (*Core) InsertMedia ¶
func (c *Core) InsertMedia(fileName, thumbName, contentType string, meta models.JSON, provider string, s media.Store) (media.Media, error)
InsertMedia inserts a new media file into the DB.
func (*Core) InsertSubscriber ¶
func (c *Core) InsertSubscriber(sub models.Subscriber, listIDs []int, listUUIDs []string, preconfirm bool) (models.Subscriber, bool, error)
InsertSubscriber inserts a subscriber and returns the ID. The first bool indicates if it was a new subscriber, and the second bool indicates if the subscriber was sent an optin confirmation. bool = optinSent?
func (*Core) QueryBounces ¶
func (c *Core) QueryBounces(campID, subID int, source, orderBy, order string, offset, limit int) ([]models.Bounce, int, error)
QueryBounces retrieves paginated bounce entries based on the given params. It also returns the total number of bounce records in the DB.
func (*Core) QueryCampaigns ¶
func (c *Core) QueryCampaigns(searchStr string, statuses, tags []string, orderBy, order string, offset, limit int) (models.Campaigns, int, error)
QueryCampaigns retrieves paginated campaigns optionally filtering them by the given arbitrary query expression. It also returns the total number of records in the DB.
func (*Core) QueryLists ¶
func (c *Core) QueryLists(searchStr, typ, optin string, tags []string, orderBy, order string, offset, limit int) ([]models.List, int, error)
QueryLists gets multiple lists based on multiple query params. Along with the paginated and sliced results, the total number of lists in the DB is returned.
func (*Core) QueryMedia ¶
func (c *Core) QueryMedia(provider string, s media.Store, query string, offset, limit int) ([]media.Media, int, error)
QueryMedia returns media entries optionally filtered by a query string.
func (*Core) QuerySubscribers ¶
func (c *Core) QuerySubscribers(query string, listIDs []int, subStatus string, order, orderBy string, offset, limit int) (models.Subscribers, int, error)
QuerySubscribers queries and returns paginated subscrribers based on the given params including the total count.
func (*Core) RecordBounce ¶
RecordBounce records a new bounce.
func (*Core) RefreshMatView ¶
RefreshMatView refreshes a Postgres materialized view.
func (*Core) RefreshMatViews ¶
RefreshMatViews refreshes all materialized views.
func (*Core) RegisterCampaignLinkClick ¶
RegisterCampaignLinkClick registers a subscriber's link click on a campaign.
func (*Core) RegisterCampaignView ¶
RegisterCampaignView registers a subscriber's view on a campaign.
func (*Core) SetDefaultTemplate ¶
SetDefaultTemplate sets a template as default.
func (*Core) UnsubscribeByCampaign ¶
UnsubscribeByCampaign unsubscribes a given subscriber from lists in a given campaign.
func (*Core) UnsubscribeLists ¶
UnsubscribeLists sets list subscriptions to 'unsubscribed'.
func (*Core) UnsubscribeListsByQuery ¶
UnsubscribeListsByQuery sets list subscriptions to 'unsubscribed' by a given arbitrary query expression. sourceListIDs is the list of list IDs to filter the subscriber query with.
func (*Core) UpdateCampaign ¶
func (c *Core) UpdateCampaign(id int, o models.Campaign, listIDs []int, mediaIDs []int, sendLater bool) (models.Campaign, error)
UpdateCampaign updates a campaign.
func (*Core) UpdateCampaignArchive ¶
func (c *Core) UpdateCampaignArchive(id int, enabled bool, tplID int, meta models.JSON, archiveSlug string) error
UpdateCampaignArchive updates a campaign's archive properties.
func (*Core) UpdateCampaignStatus ¶
UpdateCampaignStatus updates a campaign's status, eg: draft to running.
func (*Core) UpdateList ¶
UpdateList updates a given list.
func (*Core) UpdateSettings ¶
UpdateSettings updates settings.
func (*Core) UpdateSubscriber ¶
func (c *Core) UpdateSubscriber(id int, sub models.Subscriber) (models.Subscriber, error)
UpdateSubscriber updates a subscriber's properties.
func (*Core) UpdateSubscriberWithLists ¶
func (c *Core) UpdateSubscriberWithLists(id int, sub models.Subscriber, listIDs []int, listUUIDs []string, preconfirm, deleteLists bool) (models.Subscriber, bool, error)
UpdateSubscriberWithLists updates a subscriber's properties. If deleteLists is set to true, all existing subscriptions are deleted and only the ones provided are added or retained.