Documentation ¶
Overview ¶
Package subimporter implements a bulk ZIP/CSV importer of subscribers. It implements a simple queue for buffering imports and committing records to DB along with ZIP and CSV handling utilities. It is meant to be used as a singleton as each Importer instance is stateful, where it keeps track of an import in progress. Only one import should happen on a single importer instance at a time.
Index ¶
Constants ¶
const ( StatusNone = "none" StatusImporting = "importing" StatusStopping = "stopping" StatusFinished = "finished" StatusFailed = "failed" ModeSubscribe = "subscribe" ModeBlocklist = "blocklist" )
Various import statuses.
Variables ¶
var ( // ErrIsImporting is thrown when an import request is made while an // import is already running. ErrIsImporting = errors.New("import is already running") )
Functions ¶
This section is empty.
Types ¶
type Importer ¶
Importer represents the bulk CSV subscriber import system.
func (*Importer) NewSession ¶
func (im *Importer) NewSession(opt SessionOpt) (*Session, error)
NewSession returns an new instance of Session. It takes the name of the uploaded file, but doesn't do anything with it but retains it for stats.
func (*Importer) SanitizeEmail ¶
SanitizeEmail validates and sanitizes an e-mail string and returns the lowercased, e-mail component of an e-mail string.
type Options ¶
type Options struct { UpsertStmt *sql.Stmt BlocklistStmt *sql.Stmt UpdateListDateStmt *sql.Stmt NotifCB models.AdminNotifCallback // Lookup table for blocklisted domains. DomainBlocklist []string }
Options represents import options.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session represents a single import session.
func (*Session) ExtractZIP ¶
ExtractZIP takes a ZIP file's path and extracts all .csv files in it to a temporary directory, and returns the name of the temp directory and the list of extracted .csv files.
func (*Session) LoadCSV ¶
LoadCSV loads a CSV file and validates and imports the subscriber entries in it.
type SessionOpt ¶
type SessionOpt struct { Filename string `json:"filename"` Mode string `json:"mode"` SubStatus string `json:"subscription_status"` Overwrite bool `json:"overwrite"` Delim string `json:"delim"` ListIDs []int `json:"lists"` }
SessionOpt represents the options for an importer session.