package approve_former import "strings" const flowTemplate = `apiVersion: argoproj.io/v1alpha1 kind: WorkflowTemplate metadata: name: [[ .name ]] spec: entrypoint: front_json-flow arguments: parameters: - name: object value: {} templates: - name: front_json-flow inputs: parameters: - name: object steps: [[- if .childNodesContentLines ]] [[- range .childNodesContentLines ]] [[ . ]] [[- end ]] [[- else ]] - name: parse_flow template: approval [[- end ]] - name: approval suspend: {} inputs: parameters: - name: front_json default: '通过' enum: - '通过' - '拒绝' - '忽略' outputs: parameters: - name: front_json valueFrom: supplied: {}` type Flow struct { name string childNodes []Noder } func NewFlow(name string, childNodes ...Noder) *Flow { return &Flow{ name: name, childNodes: childNodes, } } func (flow *Flow) GetDepends() string { return "" } func (flow *Flow) GetWhen() string { return "" } func (flow *Flow) AddNodes(childNodes ...Noder) *Flow { if childNodes == nil || len(childNodes) == 0 { flow.childNodes = append(flow.childNodes, childNodes...) } return flow } func (flow *Flow) Render(_ Noder) (string, error) { childNodesContents := make([]string, 0) for i, childNode := range flow.childNodes { var childNodeContent string if i == 0 { content, err := childNode.Render(nil) if err != nil { return "", err } childNodeContent = content } else { content, err := childNode.Render(flow.childNodes[i-1]) if err != nil { return "", err } childNodeContent = content } childNodesContents = append(childNodesContents, strings.Split(childNodeContent, "\n")...) } return render("flow", flowTemplate, map[string]any{ "name": flow.name, "childNodesContentLines": childNodesContents, }) }