builtin.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2021 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/sink"
  18. "github.com/lf-edge/ekuiper/internal/topo/source"
  19. "github.com/lf-edge/ekuiper/pkg/api"
  20. )
  21. type NewSourceFunc func() api.Source
  22. type NewSinkFunc func() api.Sink
  23. var (
  24. sources = map[string]NewSourceFunc{
  25. "mqtt": func() api.Source { return &source.MQTTSource{} },
  26. "httppull": func() api.Source { return &source.HTTPPullSource{} },
  27. "file": func() api.Source { return &source.FileSource{} },
  28. "memory": func() api.Source { return memory.GetSource() },
  29. }
  30. sinks = map[string]NewSinkFunc{
  31. "log": sink.NewLogSink,
  32. "logToMemory": sink.NewLogSinkToMemory,
  33. "mqtt": func() api.Sink { return &sink.MQTTSink{} },
  34. "rest": func() api.Sink { return &sink.RestSink{} },
  35. "nop": func() api.Sink { return &sink.NopSink{} },
  36. "memory": func() api.Sink { return memory.GetSink() },
  37. }
  38. )
  39. type Manager struct{}
  40. func (m *Manager) Source(name string) (api.Source, error) {
  41. if s, ok := sources[name]; ok {
  42. return s(), nil
  43. }
  44. return nil, nil
  45. }
  46. func (m *Manager) Sink(name string) (api.Sink, error) {
  47. if s, ok := sinks[name]; ok {
  48. return s(), nil
  49. }
  50. return nil, nil
  51. }
  52. var m = &Manager{}
  53. func GetManager() *Manager {
  54. return m
  55. }