未验证 提交 7d05e756 编写于 作者: J JJW 提交者: GitHub

refactor(core): validate wf config (#117)

* refactor(core): validate wf config
Co-authored-by: Njjwygjj <wangyaoguang@cel.la>
上级 4d1bc810
name: Service
host: localhost
port: 9998
sinks:
- name: db
host: localhost
port: 4242
\ No newline at end of file
name: Service
host: localhost
port: 9999
sinks:
- name: receiver
host: localhost
port: 9998
\ No newline at end of file
...@@ -46,35 +46,10 @@ func validateConfig(wfConf *conf.WorkflowConfig) error { ...@@ -46,35 +46,10 @@ func validateConfig(wfConf *conf.WorkflowConfig) error {
return errors.New("conf is nil") return errors.New("conf is nil")
} }
m := map[string][]conf.App{
"Flows": wfConf.Flows,
"Sinks": wfConf.Sinks,
}
missingApps := []string{}
missingParams := []string{}
for k, apps := range m {
if len(apps) == 0 {
missingApps = append(missingApps, k)
} else {
for _, app := range apps {
if app.Name == "" || app.Host == "" || app.Port <= 0 {
missingParams = append(missingParams, k)
}
}
}
}
errMsg := "" errMsg := ""
if wfConf.Name == "" || wfConf.Host == "" || wfConf.Port <= 0 { if wfConf.Name == "" || wfConf.Host == "" || wfConf.Port <= 0 {
errMsg = "Missing name, host or port in workflow config. " errMsg = "Missing name, host or port in workflow config. "
} }
if len(missingApps) > 0 {
errMsg += "Missing apps in " + strings.Join(missingApps, ", "+". ")
}
if len(missingApps) > 0 {
errMsg += "Missing name, host or port in " + strings.Join(missingApps, ", "+". ")
}
if errMsg != "" { if errMsg != "" {
return errors.New(errMsg) return errors.New(errMsg)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册