builtin.go 3.1 KB

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