util.go 588 Bytes
Newer Older
“李磊”'s avatar
“李磊” committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package pluginmgr

import (
	"encoding/json"
	"fmt"
	"os"
)

func LoadPluginConfigWithFile(filePath string) (map[string]*PluginProcessConf, error) {
	data, err := os.ReadFile(filePath) // TODO: change to util.ReadFile
	if err != nil {
		return nil, err
	}
	return LoadPluginConfigWithData(data)
}

func LoadPluginConfigWithData(data []byte) (map[string]*PluginProcessConf, error) {
	plgCfgMap := make(map[string]*PluginProcessConf)
	err := json.Unmarshal(data, &plgCfgMap)
	if err != nil {
		return nil, fmt.Errorf("json unmarshal plugin config err: %v", err)
	}
	return plgCfgMap, nil
}