filter

package
v0.0.0-...-5628fe7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 27, 2016 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DateLayout        = "2006-01-02"
	TimeLayout        = "15:04:05"
	DateAndTimeLayout = "2006-01-02 15:04:05"
)
View Source
const (
	Check = `` /* 145-byte string literal not displayed */

)

Variables

View Source
var ErrResolveFailed = errors.New("failed to resolve expression")

Functions

func Apply

func Apply(strategies map[Type][]Strategy)

func ClearVariables

func ClearVariables(phones []string, template t.Name)

func FindVariables

func FindVariables(phone string, template t.Name) (map[string]string, bool)

func ProcessChain

func ProcessChain(phoneArray []string, template t.Name) []string

func StoreVariables

func StoreVariables(phones []string, template t.Name, variables map[string]string)

Types

type Chain

type Chain struct {
	Filter Filter
	Next   *Chain
}

func NewChain

func NewChain(filter Filter) *Chain

func (*Chain) Braid

func (c *Chain) Braid(filter Filter) *Chain

type Exp

type Exp struct {
	Begin string `json:"begin"`
	End   string `json:"end"`
}

type Filter

type Filter interface {
	Allow(phone string, template t.Name) bool
	WhichType() Type
	Apply(strategies []Strategy)
	Resolve(expression string) (interface{}, error)
}

type PostponeFilter

type PostponeFilter struct {
	Type       Type                        `bson:"type" json:"type"`
	Strategies map[t.Name]PostponeStrategy `bson:"strategies" json:"strategies"`
}

func NewPostponeFilter

func NewPostponeFilter() *PostponeFilter

func (*PostponeFilter) Allow

func (f *PostponeFilter) Allow(phone string, template t.Name) bool

func (*PostponeFilter) Apply

func (f *PostponeFilter) Apply(strategies []Strategy)

func (*PostponeFilter) Resolve

func (f *PostponeFilter) Resolve(expression string) (interface{}, error)

func (*PostponeFilter) WhichType

func (f *PostponeFilter) WhichType() Type

type PostponeStrategy

type PostponeStrategy struct {
	Begin time.Time
	End   time.Time
}

type RateLimitFilter

type RateLimitFilter struct {
	Type       Type                         `bson:"type" json:"type"`
	Strategies map[t.Name]RateLimitStrategy `bson:"strategies" json:"strategies"`
}

func NewRateLimitFilter

func NewRateLimitFilter() *RateLimitFilter

func (*RateLimitFilter) Allow

func (f *RateLimitFilter) Allow(phone string, template t.Name) bool

func (*RateLimitFilter) Apply

func (f *RateLimitFilter) Apply(strategies []Strategy)

func (*RateLimitFilter) Resolve

func (f *RateLimitFilter) Resolve(expression string) (interface{}, error)

func (*RateLimitFilter) WhichType

func (f *RateLimitFilter) WhichType() Type

type RateLimitStrategy

type RateLimitStrategy struct {
	Duration time.Duration `json:"duration"`
	Count    uint32        `json:"count"`
}

for further extention, RateLimitStrategy can hold bare script

type Strategy

type Strategy struct {
	Type       Type   `bson:"type" json:"type"`
	Template   t.Name `bson:"template" json:"template"`
	Expression string `bson:"expression" json:"expression"`
	Enabled    bool   `bson:"enabled" json:"enabled"`
}

type Type

type Type int
const (
	FilterTypeUnsubscribe Type = iota + 1
	FilterTypeRateLimit
	FilterTypePostpone
)

func (Type) String

func (t Type) String() string

type UnsubscribeFilter

type UnsubscribeFilter struct {
	Type Type `bson:"type" json:"type"`
}

func NewUnsubscribeFilter

func NewUnsubscribeFilter() *UnsubscribeFilter

func (*UnsubscribeFilter) Allow

func (f *UnsubscribeFilter) Allow(phone string, template t.Name) bool

func (*UnsubscribeFilter) Apply

func (f *UnsubscribeFilter) Apply(strategies []Strategy)

func (*UnsubscribeFilter) Resolve

func (f *UnsubscribeFilter) Resolve(expression string) (interface{}, error)

func (*UnsubscribeFilter) WhichType

func (f *UnsubscribeFilter) WhichType() Type

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL