plugin.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 plugin
  15. type PluginType int
  16. const (
  17. SOURCE PluginType = iota
  18. SINK
  19. FUNCTION
  20. PORTABLE
  21. WASM
  22. )
  23. var PluginTypes = []string{"sources", "sinks", "functions"}
  24. type Plugin interface {
  25. GetName() string
  26. GetFile() string
  27. GetShellParas() []string
  28. GetSymbols() []string
  29. SetName(n string)
  30. }
  31. // IOPlugin Unify model. Flat all properties for each kind.
  32. type IOPlugin struct {
  33. Name string `json:"name"`
  34. File string `json:"file"`
  35. ShellParas []string `json:"shellParas"`
  36. }
  37. func (p *IOPlugin) GetName() string {
  38. return p.Name
  39. }
  40. func (p *IOPlugin) GetFile() string {
  41. return p.File
  42. }
  43. func (p *IOPlugin) GetShellParas() []string {
  44. return p.ShellParas
  45. }
  46. func (p *IOPlugin) GetSymbols() []string {
  47. return nil
  48. }
  49. func (p *IOPlugin) SetName(n string) {
  50. p.Name = n
  51. }
  52. func NewPluginByType(t PluginType) Plugin {
  53. switch t {
  54. case FUNCTION:
  55. return &FuncPlugin{}
  56. default:
  57. return &IOPlugin{}
  58. }
  59. }
  60. type FuncPlugin struct {
  61. IOPlugin
  62. // Optional, if not specified, a default element with the same name of the file will be registered
  63. Functions []string `json:"functions"`
  64. }
  65. func (fp *FuncPlugin) GetSymbols() []string {
  66. return fp.Functions
  67. }