MCPcopy Create free account
hub / github.com/XmirrorSecurity/OpenSCA-cli / LoadConfig

Function LoadConfig

cmd/config/config.go:106–129  ·  view source on GitHub ↗

LoadConfig 加载配置文件 返回使用的配置文件

(filepath string)

Source from the content-addressed store, hash-verified

104
105// LoadConfig 加载配置文件 返回使用的配置文件
106func LoadConfig(filepath string) string {
107
108 if filepath == "" {
109 logs.Debug("use default config")
110 return loadDefaultConfig()
111 }
112
113 if _, err := os.Stat(filepath); err != nil {
114 logs.Debugf("%s not exist, create default config file", filepath)
115 CreateConfigFile(filepath)
116 }
117
118 f, err := os.Open(filepath)
119 if err != nil {
120 logs.Warnf("read file %s error: %v", filepath, err)
121 }
122
123 err = json5.NewDecoder(f).Decode(_config)
124 if err != nil {
125 logs.Warnf("unmarshal file %s error: %v", filepath, err)
126 }
127
128 return filepath
129}
130
131var defalutConfigJson []byte
132

Callers 1

argsFunction · 0.92

Calls 6

DebugFunction · 0.92
DebugfFunction · 0.92
WarnfFunction · 0.92
loadDefaultConfigFunction · 0.85
CreateConfigFileFunction · 0.85
DecodeMethod · 0.80

Tested by

no test coverage detected