plugin.go 1.7 KB

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