func_meta.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. "bytes"
  17. "os"
  18. "path"
  19. "strings"
  20. "github.com/lf-edge/ekuiper/internal/conf"
  21. )
  22. func readFuncMetaDir() []fileContent {
  23. var filesByte []fileContent
  24. confDir, err := conf.GetConfLoc()
  25. if nil != err {
  26. return nil
  27. }
  28. dir := path.Join(confDir, "functions")
  29. files, err := os.ReadDir(dir)
  30. if nil != err {
  31. return nil
  32. }
  33. for _, file := range files {
  34. fname := file.Name()
  35. if !strings.HasSuffix(fname, ".json") {
  36. continue
  37. }
  38. filesByte = append(filesByte, readFuncMetaFile(path.Join(dir, fname)))
  39. }
  40. confDir, err = conf.GetDataLoc()
  41. if nil != err {
  42. return nil
  43. }
  44. dir = path.Join(confDir, "functions")
  45. files, err = os.ReadDir(dir)
  46. if nil != err {
  47. return nil
  48. }
  49. for _, file := range files {
  50. fname := file.Name()
  51. if !strings.HasSuffix(fname, ".json") {
  52. continue
  53. }
  54. filesByte = append(filesByte, readFuncMetaFile(path.Join(dir, fname)))
  55. }
  56. return filesByte
  57. }
  58. func readFuncMetaFile(filePath string) fileContent {
  59. fiName := path.Base(filePath)
  60. sliByte, _ := os.ReadFile(filePath)
  61. conf.Log.Infof("funcMeta file : %s", fiName)
  62. return sliByte
  63. }
  64. func GetFunctions() bytes.Buffer {
  65. files := readFuncMetaDir()
  66. return ConstructJsonArray(files)
  67. }