builtin.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright 2021-2023 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/io/file"
  17. "github.com/lf-edge/ekuiper/internal/io/http"
  18. "github.com/lf-edge/ekuiper/internal/io/memory"
  19. "github.com/lf-edge/ekuiper/internal/io/mqtt"
  20. "github.com/lf-edge/ekuiper/internal/io/neuron"
  21. "github.com/lf-edge/ekuiper/internal/io/sink"
  22. plugin2 "github.com/lf-edge/ekuiper/internal/plugin"
  23. "github.com/lf-edge/ekuiper/pkg/api"
  24. )
  25. type NewSourceFunc func() api.Source
  26. type NewLookupSourceFunc func() api.LookupSource
  27. type NewSinkFunc func() api.Sink
  28. var (
  29. sources = map[string]NewSourceFunc{
  30. "mqtt": func() api.Source { return &mqtt.MQTTSource{} },
  31. "httppull": func() api.Source { return &http.PullSource{} },
  32. "httppush": func() api.Source { return &http.PushSource{} },
  33. "file": func() api.Source { return &file.FileSource{} },
  34. "memory": func() api.Source { return memory.GetSource() },
  35. "neuron": func() api.Source { return neuron.GetSource() },
  36. }
  37. sinks = map[string]NewSinkFunc{
  38. "log": sink.NewLogSink,
  39. "logToMemory": sink.NewLogSinkToMemory,
  40. "mqtt": func() api.Sink { return &mqtt.MQTTSink{} },
  41. "rest": func() api.Sink { return &http.RestSink{} },
  42. "nop": func() api.Sink { return &sink.NopSink{} },
  43. "memory": func() api.Sink { return memory.GetSink() },
  44. "neuron": func() api.Sink { return neuron.GetSink() },
  45. "file": func() api.Sink { return file.File() },
  46. }
  47. lookupSources = map[string]NewLookupSourceFunc{
  48. "memory": func() api.LookupSource { return memory.GetLookupSource() },
  49. }
  50. )
  51. type Manager struct{}
  52. func (m *Manager) Source(name string) (api.Source, error) {
  53. if s, ok := sources[name]; ok {
  54. return s(), nil
  55. }
  56. return nil, nil
  57. }
  58. func (m *Manager) SourcePluginInfo(name string) (plugin2.EXTENSION_TYPE, string, string) {
  59. if _, ok := sources[name]; ok {
  60. return plugin2.INTERNAL, "", ""
  61. } else {
  62. return plugin2.NONE_EXTENSION, "", ""
  63. }
  64. }
  65. func (m *Manager) LookupSource(name string) (api.LookupSource, error) {
  66. if s, ok := lookupSources[name]; ok {
  67. return s(), nil
  68. }
  69. return nil, nil
  70. }
  71. func (m *Manager) Sink(name string) (api.Sink, error) {
  72. if s, ok := sinks[name]; ok {
  73. return s(), nil
  74. }
  75. return nil, nil
  76. }
  77. func (m *Manager) SinkPluginInfo(name string) (plugin2.EXTENSION_TYPE, string, string) {
  78. if _, ok := sinks[name]; ok {
  79. return plugin2.INTERNAL, "", ""
  80. } else {
  81. return plugin2.NONE_EXTENSION, "", ""
  82. }
  83. }
  84. var m = &Manager{}
  85. func GetManager() *Manager {
  86. return m
  87. }