builtin.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2021-2022 EMQ Technologies Co., Ltd.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package io
  15. import (
  16. "github.com/lf-edge/ekuiper/internal/topo/memory"
  17. "github.com/lf-edge/ekuiper/internal/topo/neuron"
  18. "github.com/lf-edge/ekuiper/internal/topo/sink"
  19. "github.com/lf-edge/ekuiper/internal/topo/source"
  20. "github.com/lf-edge/ekuiper/pkg/api"
  21. )
  22. type NewSourceFunc func() api.Source
  23. type NewSinkFunc func() api.Sink
  24. var (
  25. sources = map[string]NewSourceFunc{
  26. "mqtt": func() api.Source { return &source.MQTTSource{} },
  27. "httppull": func() api.Source { return &source.HTTPPullSource{} },
  28. "httppush": func() api.Source { return &source.HTTPPushSource{} },
  29. "file": func() api.Source { return &source.FileSource{} },
  30. "memory": func() api.Source { return memory.GetSource() },
  31. "neuron": func() api.Source { return neuron.GetSource() },
  32. }
  33. sinks = map[string]NewSinkFunc{
  34. "log": sink.NewLogSink,
  35. "logToMemory": sink.NewLogSinkToMemory,
  36. "mqtt": func() api.Sink { return &sink.MQTTSink{} },
  37. "rest": func() api.Sink { return &sink.RestSink{} },
  38. "nop": func() api.Sink { return &sink.NopSink{} },
  39. "memory": func() api.Sink { return memory.GetSink() },
  40. "neuron": func() api.Sink { return neuron.GetSink() },
  41. }
  42. )
  43. type Manager struct{}
  44. func (m *Manager) Source(name string) (api.Source, error) {
  45. if s, ok := sources[name]; ok {
  46. return s(), nil
  47. }
  48. return nil, nil
  49. }
  50. func (m *Manager) Sink(name string) (api.Sink, error) {
  51. if s, ok := sinks[name]; ok {
  52. return s(), nil
  53. }
  54. return nil, nil
  55. }
  56. var m = &Manager{}
  57. func GetManager() *Manager {
  58. return m
  59. }