stream.go 935 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package api
  2. import (
  3. "context"
  4. "github.com/sirupsen/logrus"
  5. )
  6. type ConsumeFunc func(data interface{})
  7. type Source interface {
  8. Open(context StreamContext, consume ConsumeFunc) error
  9. }
  10. type Emitter interface {
  11. AddOutput(chan<- interface{}, string) error
  12. }
  13. type Collector interface {
  14. GetInput() (chan<- interface{}, string)
  15. }
  16. type TopNode interface {
  17. GetName() string
  18. }
  19. type Rule struct {
  20. Id string `json:"id"`
  21. Sql string `json:"sql"`
  22. Actions []map[string]interface{} `json:"actions"`
  23. Options map[string]interface{} `json:"options"`
  24. }
  25. type StreamContext interface {
  26. GetContext() context.Context
  27. GetLogger() *logrus.Entry
  28. GetRuleId() string
  29. GetOpId() string
  30. }
  31. type SinkConnector interface {
  32. Open(context.Context, chan<- error)
  33. }
  34. type Sink interface {
  35. Collector
  36. SinkConnector
  37. }
  38. type Operator interface {
  39. Emitter
  40. Collector
  41. Exec(context context.Context) error
  42. }