connectionMeta.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 meta
  15. import (
  16. "fmt"
  17. )
  18. func GetConnectionMeta(connectionName, language string) (ptrSourceProperty *uiSource, err error) {
  19. gSourcemetaLock.RLock()
  20. defer gSourcemetaLock.RUnlock()
  21. v, found := gSourcemetadata[connectionName+`.json`]
  22. if !found {
  23. return nil, fmt.Errorf(`%s%s`, getMsg(language, source, "not_found_plugin"), connectionName)
  24. }
  25. ret := make(map[string][]field)
  26. for kcfg, cfg := range v.ConfKeys {
  27. var sli []field
  28. for _, kvs := range cfg {
  29. if kvs.ConnectionRelated {
  30. sli = append(sli, kvs)
  31. }
  32. }
  33. ret[kcfg] = sli
  34. }
  35. ui := new(uiSource)
  36. *ui = *v
  37. ui.ConfKeys = ret
  38. return ui, nil
  39. }
  40. func GetConnectionPlugins() (sources []*pluginfo) {
  41. ConfigManager.lock.RLock()
  42. defer ConfigManager.lock.RUnlock()
  43. for _, conf := range ConfigManager.cfgOperators {
  44. if conf.IsSource() {
  45. continue
  46. }
  47. plugName := conf.GetPluginName()
  48. uiSourceRepKey := plugName + `.json`
  49. gSourcemetaLock.RLock()
  50. v, found := gSourcemetadata[uiSourceRepKey]
  51. if !found {
  52. gSourcemetaLock.RUnlock()
  53. continue
  54. }
  55. gSourcemetaLock.RUnlock()
  56. node := new(pluginfo)
  57. node.Name = plugName
  58. if nil == v.About {
  59. continue
  60. }
  61. node.About = v.About
  62. i := 0
  63. for ; i < len(sources); i++ {
  64. if node.Name <= sources[i].Name {
  65. sources = append(sources, node)
  66. copy(sources[i+1:], sources[i:])
  67. sources[i] = node
  68. break
  69. }
  70. }
  71. if len(sources) == i {
  72. sources = append(sources, node)
  73. }
  74. }
  75. return sources
  76. }