Documentation ¶
Overview ¶
Example (Inspect) ¶
package main import ( "context" "fmt" "github.com/jshlbrd/substation/condition" "github.com/jshlbrd/substation/config" ) func main() { // data must be gzip cfg := config.Config{ Type: "content", Settings: map[string]interface{}{ "options": map[string]interface{}{ "type": "application/x-gzip", }, }, } // inspector is retrieved from the factory inspector, err := condition.NewInspector(cfg) if err != nil { // handle err panic(err) } // inspector is applied to capsule capsule := config.NewCapsule() capsule.SetData([]byte{31, 139, 8, 0, 0, 0, 0, 0, 0, 255}) ok, err := inspector.Inspect(context.TODO(), capsule) if err != nil { // handle err panic(err) } fmt.Println(ok) }
Output: true
Example (Operate) ¶
package main import ( "context" "fmt" "github.com/jshlbrd/substation/condition" "github.com/jshlbrd/substation/config" ) func main() { // data must have a length greater than zero and contain // the substring "iz" cfg := []config.Config{ { Type: "length", Settings: map[string]interface{}{ "options": map[string]interface{}{ "type": "less_than", "value": 6, }, }, }, { Type: "strings", Settings: map[string]interface{}{ "options": map[string]interface{}{ "type": "contains", "expression": "iz", }, }, }, } // multiple inspectors are paired with an operator to // test many conditions at once opCfg := condition.Config{ Operator: "and", Inspectors: cfg, } // operator is retrieved from the factory operator, err := condition.NewOperator(opCfg) if err != nil { // handle err panic(err) } // operator is applied to capsule capsule := config.NewCapsule() capsule.SetData([]byte("fizzy")) ok, err := operator.Operate(context.TODO(), capsule) if err != nil { // handle err panic(err) } fmt.Println(ok) }
Output: true
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InspectBytes ¶
InspectByte is a convenience function for applying an Inspector to bytes.
Example ¶
package main import ( "context" "fmt" "github.com/jshlbrd/substation/condition" "github.com/jshlbrd/substation/config" ) func main() { // data must be gzip cfg := config.Config{ Type: "content", Settings: map[string]interface{}{ "options": map[string]interface{}{ "type": "application/x-gzip", }, }, } // inspector is retrieved from the factory inspector, err := condition.NewInspector(cfg) if err != nil { // handle err panic(err) } // inspector is applied to bytes b := []byte{31, 139, 8, 0, 0, 0, 0, 0, 0, 255} ok, err := condition.InspectBytes(context.TODO(), b, inspector) if err != nil { // handle err panic(err) } fmt.Println(ok) }
Output: true
func OperateBytes ¶
OperateBytes is a convenience function for applying an Operator to bytes.
Example ¶
package main import ( "context" "fmt" "github.com/jshlbrd/substation/condition" "github.com/jshlbrd/substation/config" ) func main() { // data must have a length greater than zero and contain // the substring "iz" cfg := []config.Config{ { Type: "length", Settings: map[string]interface{}{ "options": map[string]interface{}{ "type": "less_than", "value": 6, }, }, }, { Type: "strings", Settings: map[string]interface{}{ "options": map[string]interface{}{ "type": "contains", "expression": "iz", }, }, }, } // multiple inspectors are paired with an operator to // test many conditions at once opCfg := condition.Config{ Operator: "and", Inspectors: cfg, } // operator is retrieved from the factory operator, err := condition.NewOperator(opCfg) if err != nil { // handle err panic(err) } // operator is applied to bytes b := []byte("fizzy") ok, err := condition.OperateBytes(context.TODO(), b, operator) if err != nil { // handle err panic(err) } fmt.Println(ok) }
Output: true
Types ¶
type Config ¶
type Config struct { Operator string `json:"operator"` Inspectors []config.Config `json:"inspectors"` }
Config is used with NewOperator to produce new operators.
type Inspector ¶
func NewInspector ¶
NewInspector returns a configured Inspector from an Inspector configuration.
Example ¶
package main import ( "fmt" "github.com/jshlbrd/substation/condition" "github.com/jshlbrd/substation/config" ) func main() { // data must be gzip cfg := config.Config{ Type: "content", Settings: map[string]interface{}{ "options": map[string]interface{}{ "type": "application/x-gzip", }, }, } // inspector is retrieved from the factory inspector, err := condition.NewInspector(cfg) if err != nil { // handle err panic(err) } fmt.Println(inspector) }
Output:
func NewInspectors ¶
NewInspectors accepts one or more Inspector configurations and returns configured inspectors.
Example ¶
package main import ( "fmt" "github.com/jshlbrd/substation/condition" "github.com/jshlbrd/substation/config" ) func main() { // data must be gzip cfg := config.Config{ Type: "content", Settings: map[string]interface{}{ "options": map[string]interface{}{ "type": "application/x-gzip", }, }, } // one or more inspectors are created inspectors, err := condition.NewInspectors(cfg) if err != nil { // handle err panic(err) } for _, ins := range inspectors { fmt.Println(ins) } }
Output:
type Operator ¶
func NewOperator ¶
NewOperator returns a configured Operator from an Operator configuration.
Example ¶
package main import ( "fmt" "github.com/jshlbrd/substation/condition" "github.com/jshlbrd/substation/config" ) func main() { // data must have a length greater than zero and contain // the substring "iz" cfg := []config.Config{ { Type: "length", Settings: map[string]interface{}{ "options": map[string]interface{}{ "type": "greater_than", "value": 0, }, }, }, { Type: "strings", Settings: map[string]interface{}{ "options": map[string]interface{}{ "type": "contains", "expression": "iz", }, }, }, } // multiple inspectors are paired with an operator to // test many conditions at once. opCfg := condition.Config{ Operator: "and", Inspectors: cfg, } // operators are retrieved from the factory. operator, err := condition.NewOperator(opCfg) if err != nil { // handle err panic(err) } fmt.Println(operator) }
Output:
Click to show internal directories.
Click to hide internal directories.