builtin.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. )
  45. type Manager struct{}
  46. func (m *Manager) Source(name string) (api.Source, error) {
  47. if s, ok := sources[name]; ok {
  48. return s(), nil
  49. }
  50. return nil, nil
  51. }
  52. func (m *Manager) LookupSource(name string) (api.LookupSource, error) {
  53. if s, ok := lookupSources[name]; ok {
  54. return s(), nil
  55. }
  56. return nil, nil
  57. }
  58. func (m *Manager) Sink(name string) (api.Sink, error) {
  59. if s, ok := sinks[name]; ok {
  60. return s(), nil
  61. }
  62. return nil, nil
  63. }
  64. var m = &Manager{}
  65. func GetManager() *Manager {
  66. return m
  67. }