package approve_former import "strings" type Or struct { childNodes []Node } func NewOr(childNodes ...Node) *Or { return &Or{ childNodes: childNodes, } } func (or *Or) GetDepends() string { var depends string for _, childNode := range or.childNodes { if depends == "" { depends = childNode.GetDepends() } else { depends = depends + " && " + childNode.GetDepends() } } return depends } func (or *Or) GetWhen() string { var when string for _, childNode := range or.childNodes { if when == "" { when = "(" + childNode.GetWhen() + ")" } else { when = when + " || " + "(" + childNode.GetWhen() + ")" } } return when } func (or *Or) AddNodes(childNodes ...Node) *Or { if childNodes == nil || len(childNodes) == 0 { or.childNodes = append(or.childNodes, childNodes...) } return or } func (or *Or) Render(upperNode Node) (string, error) { var content string for _, childNode := range or.childNodes { childNodeContent, err := childNode.Render(upperNode) if err != nil { return "", err } content = content + childNodeContent + "\n" } content = strings.TrimSuffix(content, "\n") return content, nil }