builtin.go 1.7 KB

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