Documentation ¶
Overview ¶
Package notify provides simple way to create notify server.
Creating a server is easy as
- Select and initialize a db driver (see ./model/mysqldrv)
- Select and initialize few notify driver (see ./drivers/...)
- Create a configuration (see SenderOptions)
- Create a server with SenderOptions, and Register() your drivers
- ListenAndServe(), enjoy it
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type APIServer ¶
type APIServer interface { // register supported drivers, you *MUST* register all needed drivers // before starting server. Register(types.Driver) // start the api server and bind it to addr. It also starts internal worker // to send notification. Start() error // start the api server and bind it to addr, with basic TLS settings. It // also starts internal worker to send notification. StartTLS(certFile, keyFile string) error // gracefully shutdown the api server and internal worker. Shutdown(ctx context.Context) (err error) // returns the http.Server so you can customize it. Do not start it by // yourself, or internal worker will not start. GetHTTPServer() (ret *http.Server) }
APIServer defines an API server to accept notification-sending requests.
API format ¶
Parameters are passed in JSON format using HTTP POST request. "Content-Type" header is ignored. The result of request is returned in HTTP status code.
API Endpoints
- /send: Send notification and retry automatically if not delivered. See types. Params struct for details of parameters.
- /sendOnce: Send notification, does not retry. See Params struct for details of parameters.
- /resend: Force resend a notification, does not retry. The only accpeted parameter is {"id": string}.
- /result: Retrieve latest sending result. The only accpeted parameter is {"id": string}.
- /status: Retrieve status of a notification, see types.Status for detail. It accepts only one parameter {"id": string}.
- /detail: Retrieve detail of a notification, see types.Detail for detail. It accepts only one parameter {"id": string}.
- /delete: Deletes a notification, does not interrupt if worker is sending it. The only accpeted parameter is {"id": string}.
- /clear: Deletes outdated, finished jobs (status IN(SUCCESS, FAILED)). The only accepted parameter is {"before": unix timestamp}.
- /forceClear: Deletes all outdated jobs The only accepted parameter is {"before": unix timestamp}.
Jobs allocated by a worker will not be deleted by /delete, /clear nor /forceClear.
type SenderOptions ¶
type SenderOptions struct { // how many times to retry before considering as FAILED. // which means 1 = do not resend. // besides, 0 = math.MaxUint32. MaxTries uint32 // user provided scheduler. nil uses DefaultScheduler Scheduler types.Scheduler // how many goroutines to do the sending job. // 0 will be updated to 1 when creating sender. MaxThreads uint16 // db driver, required model.DBDrv }
SenderOptions defines configurations of internal worker
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
notify-api
Command notify-api is predefined binary with provided drivers using MySQL.
|
Command notify-api is predefined binary with provided drivers using MySQL. |
notify-api-pg
Command notify-api-pg is predefined binary with provided drivers using PosgreSQL.
|
Command notify-api-pg is predefined binary with provided drivers using PosgreSQL. |
drivers
|
|
httpdrv
Package httpdrv defines two http based drivers.
|
Package httpdrv defines two http based drivers. |
sendgriddrv
Package sendgriddrv sends notification email with sendgrid API
|
Package sendgriddrv sends notification email with sendgrid API |
smsav8d
Package smsav8d provides a driver to send SMS using https://www.teamplus.tech/product/every8d-value/
|
Package smsav8d provides a driver to send SMS using https://www.teamplus.tech/product/every8d-value/ |
smtpdrv
Package smtpdrv sends notification email using net/smtp This driver is not mean to be high performance, just provides a simple way to send email without applying external services other than your mailbox.
|
Package smtpdrv sends notification email using net/smtp This driver is not mean to be high performance, just provides a simple way to send email without applying external services other than your mailbox. |
tgdrv
Package tgdrv provides a driver that send telegram message
|
Package tgdrv provides a driver that send telegram message |
Package model encapsules db operations.
|
Package model encapsules db operations. |
dbdrvtest
Package dbdrvtest provides needed integral test for db driver writer.
|
Package dbdrvtest provides needed integral test for db driver writer. |
mysqldrv
Package mysqldrv provides mysql db driver This driver is tested with github.com/go-sql-driver/mysql against mysql 5.7/8
|
Package mysqldrv provides mysql db driver This driver is tested with github.com/go-sql-driver/mysql against mysql 5.7/8 |
pgsqldrv
Package pgsqldrv provides postgresql db driver This driver is tested with github.com/jackc/pgx/v4 against postgres 9~13
|
Package pgsqldrv provides postgresql db driver This driver is tested with github.com/jackc/pgx/v4 against postgres 9~13 |
Package types defines common types used in package notify, model and drivers
|
Package types defines common types used in package notify, model and drivers |
Click to show internal directories.
Click to hide internal directories.