plugin.go 1.7 KB

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