functionbuilder again
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-11-21 14:14:28 +11:00
parent d431eadbcc
commit e4392acbe3
5 changed files with 292 additions and 122 deletions

View File

@@ -86,9 +86,7 @@ func PostDirektivHandle(params PostParams) middleware.Responder {
// if foreach returns an error there is no continue
//
// default we do not continue
cont = convertTemplateToBool("<no value>", accParams, false)
// cont = convertTemplateToBool("<no value>", accParams, true)
// cont = false
//
if err != nil && !cont {
@@ -163,34 +161,65 @@ func PostDirektivHandle(params PostParams) middleware.Responder {
return NewPostOK().WithPayload(resp)
}
// exec
// foreach command
type LoopStruct0 struct {
accParams
Item interface{}
DirektivDir string
}
func runCommand0(ctx context.Context,
params accParams, ri *apps.RequestInfo) (map[string]interface{}, error) {
params accParams, ri *apps.RequestInfo) ([]map[string]interface{}, error) {
ir := make(map[string]interface{})
ir[successKey] = false
var cmds []map[string]interface{}
at := accParamsTemplate{
*params.Body,
params.Commands,
params.DirektivDir,
if params.Body == nil {
return cmds, nil
}
cmd, err := templateString(`/bin/json2excel -inputJson {{- if eq (deref .Infile) "" }} "input.json" {{- else }} {{ .Infile }} {{- end }} -worksheetName "{{ .WorksheetName }}" -outputFilename '{{ .OutFilename }}'`, at)
if err != nil {
ri.Logger().Infof("error executing command: %v", err)
ir[resultKey] = err.Error()
return ir, err
for a := range params.Body.Sheets {
ls := &LoopStruct0{
params,
params.Body.Sheets[a],
params.DirektivDir,
}
cmd, err := templateString(`/bin/json2excel -inputJson {{- if eq (deref .Item.Infile) "" }} "input.json" {{- else }} {{ .Item.Infile }} {{- end }} -worksheetName "{{ .Item.WorksheetName }}" -outputFilename '{{ .OutFilename }}'`, ls)
if err != nil {
ir := make(map[string]interface{})
ir[successKey] = false
ir[resultKey] = err.Error()
cmds = append(cmds, ir)
continue
}
silent := convertTemplateToBool("false", ls, false)
print := convertTemplateToBool("true", ls, true)
cont := convertTemplateToBool("<no value>", ls, false)
output := ""
envs := []string{}
r, err := runCmd(ctx, cmd, envs, output, silent, print, ri)
if err != nil {
ir := make(map[string]interface{})
ir[successKey] = false
ir[resultKey] = err.Error()
cmds = append(cmds, ir)
if cont {
continue
}
return cmds, err
}
cmds = append(cmds, r)
}
cmd = strings.Replace(cmd, "\n", "", -1)
silent := convertTemplateToBool("false", at, false)
print := convertTemplateToBool("true", at, true)
output := ""
envs := []string{}
return runCmd(ctx, cmd, envs, output, silent, print, ri)
return cmds, nil
}