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

Function loadDefaultConfig

cmd/config/config.go:73–103  ·  view source on GitHub ↗

loadDefaultConfig 加载默认配置 返回使用的配置文件

()

Source from the content-addressed store, hash-verified

71
72// loadDefaultConfig 加载默认配置 返回使用的配置文件
73func loadDefaultConfig() string {
74
75 var defaultConfigPaths []string
76
77 // 读取工作目录的 config.json
78 if p, err := os.Getwd(); err == nil {
79 defaultConfigPaths = append(defaultConfigPaths, filepath.Join(p, "config.json"))
80 }
81
82 // 读取用户目录下的 opensca_config.json
83 if currenUser, err := user.Current(); err == nil {
84 defaultConfigPaths = append(defaultConfigPaths, filepath.Join(currenUser.HomeDir, "opensca_config.json"))
85 }
86
87 // 读取 opensca-cli 所在目录下的 config.json
88 if p, err := os.Executable(); err == nil {
89 defaultConfigPaths = append(defaultConfigPaths, filepath.Join(filepath.Dir(p), "config.json"))
90 }
91
92 for _, config := range defaultConfigPaths {
93 if data, err := os.ReadFile(config); err == nil {
94 err := json5.Unmarshal(data, &_config)
95 if err == nil {
96 logs.Debugf("load config %s", config)
97 return config
98 }
99 }
100 }
101
102 return ""
103}
104
105// LoadConfig 加载配置文件 返回使用的配置文件
106func LoadConfig(filepath string) string {

Callers 1

LoadConfigFunction · 0.85

Calls 1

DebugfFunction · 0.92

Tested by

no test coverage detected