builtin.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 NewLookupSourceFunc func() api.LookupSource
  24. type NewSinkFunc func() api.Sink
  25. var (
  26. sources = map[string]NewSourceFunc{
  27. "mqtt": func() api.Source { return &source.MQTTSource{} },
  28. "httppull": func() api.Source { return &source.HTTPPullSource{} },
  29. "httppush": func() api.Source { return &source.HTTPPushSource{} },
  30. "file": func() api.Source { return &source.FileSource{} },
  31. "memory": func() api.Source { return memory.GetSource() },
  32. "neuron": func() api.Source { return neuron.GetSource() },
  33. }
  34. sinks = map[string]NewSinkFunc{
  35. "log": sink.NewLogSink,
  36. "logToMemory": sink.NewLogSinkToMemory,
  37. "mqtt": func() api.Sink { return &sink.MQTTSink{} },
  38. "rest": func() api.Sink { return &sink.RestSink{} },
  39. "nop": func() api.Sink { return &sink.NopSink{} },
  40. "memory": func() api.Sink { return memory.GetSink() },
  41. "neuron": func() api.Sink { return neuron.GetSink() },
  42. }
  43. lookupSources = map[string]NewLookupSourceFunc{
  44. "memory": func() api.LookupSource { return memory.GetLookupSource() },
  45. }
  46. )
  47. type Manager struct{}
  48. func (m *Manager) Source(name string) (api.Source, error) {
  49. if s, ok := sources[name]; ok {
  50. return s(), nil
  51. }
  52. return nil, nil
  53. }
  54. func (m *Manager) LookupSource(name string) (api.LookupSource, error) {
  55. if s, ok := lookupSources[name]; ok {
  56. return s(), nil
  57. }
  58. return nil, nil
  59. }
  60. func (m *Manager) Sink(name string) (api.Sink, error) {
  61. if s, ok := sinks[name]; ok {
  62. return s(), nil
  63. }
  64. return nil, nil
  65. }
  66. var m = &Manager{}
  67. func GetManager() *Manager {
  68. return m
  69. }