Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyToFilter(f Filter, conds []*Condition) error
- func CheckRequiredContent(c Content, fields []string) []string
- func CheckRequiredContentError(c Content, fields []string) error
- func IsErrConditionNotSupported(err error) bool
- func IsErrInvalidConditionValue(err error) bool
- func IsErrInvalidContent(err error) bool
- func IsErrNotificationIDNotFound(err error) bool
- type Checker
- type CheckerFunc
- type Condition
- type ConditionContext
- type Content
- type ErrConditionNotSupported
- type ErrInvalidConditionValue
- type ErrInvalidContent
- type ErrNotificationIDNotFound
- type Filter
- type HasHeaderChecker
- type Header
- type NopStore
- func (n NopStore) Close() error
- func (n NopStore) Count(condition []*Condition) (int, error)
- func (n NopStore) List(condition []*Condition, start string, asc bool, count int) (result []*Notification, iter string, err error)
- func (n NopStore) Open() error
- func (n NopStore) Remove(id string) (*Notification, error)
- func (n NopStore) Save(notification *Notification) error
- func (n NopStore) SupportedConditions() ([]string, error)
- type Notification
- type PlainFilter
- type Searchable
- type Sender
- type SenderFunc
- type Store
Constants ¶
const ( //ConditionTopic store serach condition keyword for notification topic ConditionTopic = "topic" //ConditionNotificationID store serach condition keyword for notification id ConditionNotificationID = "notificationid" //ConditionTarget store serach condition keyword for notification target ConditionTarget = "target" //ConditionBatch store serach condition keyword for notification batch id ConditionBatch = "batch" //ConditionInContent store serach condition keyword for text in notification content ConditionInContent = "incontent" //ConditionSender store serach condition keyword for text in notification delivery keyword ConditionSender = "sender" //ConditionDelivery store serach condition keyword for text in notification delivery keyword ConditionDelivery = "delivery" //ConditionBeforeTimestamp store serach condition keyword for notification created-time before given timestamp ConditionBeforeTimestamp = "beforetimestamp" //ConditionAfterTimestamp store serach condition keyword for notification created-time after given timestamp ConditionAfterTimestamp = "aftertimestamp" //ConditionExpired store serach condition keyword for notification expired before given timestamp ConditionExpired = "expired" )
const ( //ErrnoSuccess error no for success delivery. ErrnoSuccess = int32(0) //ErrnoInvalidContent error rasied when content invalid ErrnoInvalidContent = int32(1000) )
const ( //HeaderNameTarget header name for message targe HeaderNameTarget = "target" //HeaderNameBatch header name for notification batch id HeaderNameBatch = "batch" //HeaderNameMessage header name for mesage id HeaderNameMessage = "mesasge" //HeaderNameTopic header name for message topic HeaderNameTopic = "topic" //HeaderNameSender header name for message sender HeaderNameSender = "sender" //HeaderNameDraftMode header name for draft-mode HeaderNameDraftMode = "draftmode" )
const DefaultStoreListLimit = 10
DefaultStoreListLimit default store list limit
Variables ¶
var CheckerAlways = CheckerFunc(func(n *Notification) (bool, error) { return true, nil })
var CheckerNever = CheckerFunc(func(n *Notification) (bool, error) { return false, nil })
var ErrStoreFeatureNotSupported = errors.New("store feature not supported")
ErrStoreFeatureNotSupported error raised when store feature not supported
var InvalidContentTypeRequired = "required"
var PlainFilterSupportedConditions = []string{ ConditionBatch, ConditionNotificationID, ConditionDelivery, ConditionTarget, ConditionTopic, ConditionInContent, ConditionBeforeTimestamp, ConditionAfterTimestamp, ConditionSender, ConditionExpired, }
PlainFilterSupportedConditions plain filter suppoerted conditions
var SuggestedNotificationTTL = 24 * time.Hour
SuggestedNotificationTTL suggrested notification ttl
Functions ¶
func ApplyToFilter ¶
ApplyToFilter apply condiitons to filter.
func CheckRequiredContent ¶
CheckRequiredContent check if fields in content. If give fields is not in missed fields will be returned.
func CheckRequiredContentError ¶
CheckRequiredContentError check if fields in content. If give fields is not in content,InvalidContentError will be returned. Otherwise nil will be returned.
func IsErrConditionNotSupported ¶
IsErrConditionNotSupported check if given error is ErrConditionNotSupported
func IsErrInvalidConditionValue ¶
IsErrInvalidConditionValue check if given error is ErrInvalidConditionValue
func IsErrInvalidContent ¶
IsErrInvalidContent check if given error is invalid content error.
func IsErrNotificationIDNotFound ¶
IsErrNotificationIDNotFound check if given error is ErrNotificationIDNotFound.
Types ¶
type Checker ¶
type Checker interface {
Check(n *Notification) (bool, error)
}
Checker notification checker interface Return if notification passed check
type CheckerFunc ¶
type CheckerFunc func(n *Notification) (bool, error)
func (CheckerFunc) Check ¶
func (f CheckerFunc) Check(n *Notification) (bool, error)
type Condition ¶
type Condition struct {
//Keyword condition keyword
Keyword string
//Value condition value to filter notification
Value string
}
Condition store search condition
type ConditionContext ¶
func NewConditionContext ¶
func NewConditionContext() *ConditionContext
type Content ¶
Content notification content type Content stores all messages in notification.
func (Content) Get ¶
Get get give value with given name from content Name will be converted to lower
type ErrConditionNotSupported ¶
type ErrConditionNotSupported struct {
Condition string
}
ErrConditionNotSupported error rasied when condition not supproted
func NewErrConditionNotSupported ¶
func NewErrConditionNotSupported(condition string) *ErrConditionNotSupported
NewErrConditionNotSupported create new ErrConditionNotSupported
func (*ErrConditionNotSupported) Error ¶
func (e *ErrConditionNotSupported) Error() string
Error return error message
type ErrInvalidConditionValue ¶
type ErrInvalidConditionValue struct {
Condition string
}
ErrInvalidConditionValue error raised when condition value invalid
func NewErrInvalidConditionValue ¶
func NewErrInvalidConditionValue(condition string) *ErrInvalidConditionValue
NewErrInvalidConditionValue create new ErrInvalidConditionValue
func (*ErrInvalidConditionValue) Error ¶
func (e *ErrInvalidConditionValue) Error() string
Error return error message
type ErrInvalidContent ¶
func NewErrInvalidContent ¶
func NewErrInvalidContent(t string, fields ...string) *ErrInvalidContent
func NewRequiredContentError ¶
func NewRequiredContentError(fields []string) *ErrInvalidContent
NewRequiredContentError create required content error with given fields.
func (*ErrInvalidContent) Error ¶
func (e *ErrInvalidContent) Error() string
type ErrNotificationIDNotFound ¶
type ErrNotificationIDNotFound struct {
NID string
}
ErrNotificationIDNotFound error raised if given notification not found
func NewErrNotificationIDNotFound ¶
func NewErrNotificationIDNotFound(nid string) *ErrNotificationIDNotFound
NewErrNotificationIDNotFound create new ErrNotificationIDNotFound
func (*ErrNotificationIDNotFound) Error ¶
func (e *ErrNotificationIDNotFound) Error() string
Error return error message
type Filter ¶
type Filter interface {
//FilterNotification filter notification with given timestamp
//Return if notification is valid
FilterNotification(n *Notification, ctx *ConditionContext) (bool, error)
//ApplyCondition apply search condition to filter
//ErrConditionNotSupported should be returned if condition keyword is not supported
ApplyCondition(cond *Condition) error
}
Filter notification filter interface
type HasHeaderChecker ¶
type HasHeaderChecker string
func (HasHeaderChecker) Check ¶
func (c HasHeaderChecker) Check(n *Notification) (bool, error)
type Header ¶
Header notification header struct
func (Header) Range ¶
Range range over header with given function. Stop range if function return false,
type NopStore ¶
type NopStore struct{}
func (NopStore) List ¶
func (n NopStore) List(condition []*Condition, start string, asc bool, count int) (result []*Notification, iter string, err error)
List list no more than count notifactions in store with given search conditions form start position . Count should be greater than 0. Found notifications and next list position iter will be returned. Return largest id notification if asc is false.
func (NopStore) Remove ¶
func (n NopStore) Remove(id string) (*Notification, error)
Remove remove notification by given id and return removed notification.
func (NopStore) Save ¶
func (n NopStore) Save(notification *Notification) error
Save save given notificaiton to store. Notification with same id will be overwritten.
func (NopStore) SupportedConditions ¶
SupportedConditions return supported condition keyword list
type Notification ¶
type Notification struct {
//ID notification id
ID string
//Delivery notification delivery keyword
Delivery string
//CreatedTime notification created unix timestmamp
CreatedTime int64
//ExpiredTime notification expired unix timestamp
//ExpiredTime 0 or less than 0 means never expired
ExpiredTime int64
//Header notification header
Header Header
//Content notification content
Content Content
}
Notification notification struct
func (*Notification) String ¶
func (n *Notification) String() string
String return notification info in string format
type PlainFilter ¶
type PlainFilter struct {
BatchID string
NotificationID string
Delivery string
Target string
Topic string
Sender string
InContent string
After int64
Before int64
Expired bool
}
PlainFilter plain filter struct
func (*PlainFilter) ApplyCondition ¶
func (c *PlainFilter) ApplyCondition(cond *Condition) error
ApplyCondition apply search condition to filter ErrConditionNotSupported should be returned if condition keyword is not supported
func (*PlainFilter) FilterNotification ¶
func (c *PlainFilter) FilterNotification(n *Notification, ctx *ConditionContext) (bool, error)
FilterNotification filter notification with given timestamp Return if notification is valid
type Searchable ¶
type Searchable interface {
//Count count store with given search conditions
Count(condition []*Condition) (int, error)
//SupportedConditions return supported condition keyword list
SupportedConditions() ([]string, error)
}
Searchable searchable interface
type Sender ¶
type Sender interface {
//Send send notification and return any error if raised.
Send(*Notification) error
}
Sender sender interafce
type SenderFunc ¶
type SenderFunc func(*Notification) error
SenderFunc sender func interface
func (SenderFunc) Send ¶
func (f SenderFunc) Send(n *Notification) error
Send send notification and return any error if raised.
type Store ¶
type Store interface {
//Open open store and return any error if raised
Open() error
//Close close store and return any error if raised
Close() error
//Save save given notificaiton to store.
//Notification with same id will be overwritten.
Save(notification *Notification) error
//List list no more than count notifactions in store with given search conditions form start position .
//Count should be greater than 0.
//Found notifications and next list position iter will be returned.
//Return largest id notification if asc is false.
List(condition []*Condition, start string, asc bool, count int) (result []*Notification, iter string, err error)
//Count count store with given search conditions
Count(condition []*Condition) (int, error)
//SupportedConditions return supported condition keyword list
SupportedConditions() ([]string, error)
//Remove remove notification by given id and return removed notification.
Remove(id string) (*Notification, error)
}
Store notitication store interface