package approve_former import "strings" const flowTemplate = `apiVersion: argoproj.io/v1alpha1 kind: WorkflowTemplate metadata: name: [[ .name ]] spec: entrypoint: approve-flow arguments: parameters: - name: object value: {} templates: - name: approve-flow inputs: parameters: - name: object dag: tasks: [[- if .childNodesContentLines ]] [[- range .childNodesContentLines ]] [[ . ]] [[- end ]] [[- else ]] - name: node template: approval [[- end ]] - name: approval suspend: {} inputs: parameters: - name: approve default: '通过' enum: - '通过' - '拒绝' - '忽略' outputs: parameters: - name: approve valueFrom: supplied: {}` type Flow struct { Name string ChildNodes []Node } func NewFlow(name string, childNodes ...Node) *Flow { return &Flow{ Name: name, ChildNodes: childNodes, } } func (flow *Flow) GetDepends() string { return "" } func (flow *Flow) GetWhen() string { return "" } func (flow *Flow) Render(_ Node) (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, }) }