engine

package
v0.0.0-...-4c70c96 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2014 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

action

engine document

expression.go

notification.go

operators

rulejson.go

Index

Constants

View Source
const (
	SMS = ActionType(iota + 1)
	EMAIL
	UPDATE
	HTTP
)

QUE TODO VAYA POR HTTP CON DIFERENTES PLANTILLAS INTERNAS?????

View Source
const (
	EQ = Op(iota + 1)
	NE
	LT
	GT
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action interface {
	Do(n *Notif) error
	Data() *ActionData
}

func NewAction

func NewAction(actionType ActionType, templateString string, parameters map[string]string) (axn Action, err error)

type ActionData

type ActionData struct {
	Type         ActionType
	TemplateText string
	Parameters   map[string]string
	// contains filtered or unexported fields
}

func (*ActionData) Data

func (ad *ActionData) Data() *ActionData

type ActionJSON

type ActionJSON struct {
	Type       string            `json:"type"`
	Template   string            `json:"template"`
	Parameters map[string]string `json:"params"`
}

type ActionType

type ActionType int

func ParseActionType

func ParseActionType(s string) (at ActionType, err error)

func (ActionType) String

func (t ActionType) String() string

type Attribute

type Attribute struct {
	Name  string
	Type  string
	Value string
}

type CondJSON

type CondJSON struct {
	Type string         `json:"type"`
	Expr [3]interface{} `json:"expr"`
}

type Condition

type Condition struct {
	Op       Op
	Exp1     Expression
	Exp2     Expression
	IsNumber bool
}

func (*Condition) Matched

func (c *Condition) Matched(n *Notif) (matched bool, err error)

type ContextElement

type ContextElement struct {
	Id         string
	IsPattern  string
	Type       string
	Attributes []Attribute
}

type EmailAction

type EmailAction struct {
	*ActionData
}

func (*EmailAction) Do

func (a *EmailAction) Do(n *Notif) (err error)

type Engine

type Engine struct {
	Rules map[string]*Rule //Too simple, better data structure/s is/are required. Only for starting
	sync.RWMutex
}

func NewEngine

func NewEngine() (eng *Engine, err error)

func (*Engine) AddRule

func (e *Engine) AddRule(r *Rule) (err error)

func (*Engine) DeleteRule

func (e *Engine) DeleteRule(id string) (err error)

func (*Engine) GetAllRules

func (e *Engine) GetAllRules() (rs []*Rule, err error)

func (*Engine) GetRule

func (e *Engine) GetRule(id string) (r *Rule, err error)

func (*Engine) Process

func (e *Engine) Process(n *Notif) (err error)

type ErrorNotFound

type ErrorNotFound struct {
	Field string
	Part  string
	Notif *Notif
}

func (*ErrorNotFound) Error

func (e *ErrorNotFound) Error() string

type Expression

type Expression struct {
	Reference string
	Text      string
	Number    float64
}

func (Expression) ToRuleJSON

func (e Expression) ToRuleJSON() interface{}

type HTTPAction

type HTTPAction struct {
	*ActionData
}

func (*HTTPAction) Do

func (a *HTTPAction) Do(n *Notif) error

type Notif

type Notif struct {
	ID       string
	Received time.Time
	Data     map[string]interface{}
}

func NewNotif

func NewNotif(data []byte) (n *Notif, err error)

func NewNotifFromCB

func NewNotifFromCB(ngsi []byte, service int) (n *Notif, err error)

func (*Notif) GetNumber

func (n *Notif) GetNumber(exp string) (number float64, err error)

func (*Notif) GetString

func (n *Notif) GetString(exp string) (str string, err error)

type NotifyContextRequest

type NotifyContextRequest struct {
	SubscriptionId   string
	Originator       string
	ContextResponses []struct{ ContextElement ContextElement }
}

type Op

type Op int

func (Op) String

func (o Op) String() string

type Rule

type Rule struct {
	ID     string
	Conds  []Condition
	Action Action
}

func NewRule

func NewRule(body []byte) (r *Rule, err error)

func (*Rule) Do

func (r *Rule) Do(n *Notif) (err error)

func (*Rule) Matched

func (r *Rule) Matched(n *Notif) (matched bool, err error)

func (*Rule) RuleJSON

func (r *Rule) RuleJSON() (rj *RuleJSON)

type RuleJSON

type RuleJSON struct {
	ID     string     `json:"id,omitempty"`
	And    []CondJSON `json:"and"`
	Action ActionJSON `json:"axn"`
}

func ParseRuleJSON

func ParseRuleJSON(data []byte) (rj *RuleJSON, err error)

func (*RuleJSON) Rule

func (rj *RuleJSON) Rule() (pr *Rule, err error)

func (*RuleJSON) ToJSON

func (rj *RuleJSON) ToJSON() ([]byte, error)

type SMSAction

type SMSAction struct {
	*ActionData
}

func (*SMSAction) Do

func (a *SMSAction) Do(n *Notif) (err error)

type UpdateAction

type UpdateAction struct {
	*ActionData
}

func (*UpdateAction) Do

func (a *UpdateAction) Do(n *Notif) error

Jump to

Keyboard shortcuts

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