Skip to content

Commit

Permalink
refactor(core): validate wf config (#117)
Browse files Browse the repository at this point in the history
* refactor(core): validate wf config

Co-authored-by: jjwygjj <[email protected]>
  • Loading branch information
JJW and jjwygjj authored Jan 26, 2021
1 parent 4d1bc81 commit 7d05e75
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 25 deletions.
7 changes: 7 additions & 0 deletions example/receiver/workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: Service
host: localhost
port: 9998
sinks:
- name: db
host: localhost
port: 4242
7 changes: 7 additions & 0 deletions example/sender/workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: Service
host: localhost
port: 9999
sinks:
- name: receiver
host: localhost
port: 9998
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
Expand Down
25 changes: 0 additions & 25 deletions internal/cmd/wf/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,35 +46,10 @@ func validateConfig(wfConf *conf.WorkflowConfig) error {
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 := ""
if wfConf.Name == "" || wfConf.Host == "" || wfConf.Port <= 0 {
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 != "" {
return errors.New(errMsg)
Expand Down

0 comments on commit 7d05e75

Please sign in to comment.