main.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package main
  2. import (
  3. "git.sxidc.com/go-tools/argo-api/approve_former"
  4. "os"
  5. )
  6. const dir = "/Users/duyong/workspace/fangshi/meta-business/argo/example/template-render/"
  7. func main() {
  8. //simpleTemp()
  9. buildSignsTemp()
  10. buildAndORTemp()
  11. }
  12. // simpleTemp 什么也没有的流程
  13. func simpleTemp() {
  14. flow := approve_former.NewFlow("simple")
  15. templateString, err := flow.Render(nil)
  16. if err != nil {
  17. panic(err)
  18. }
  19. _ = writeFile(dir+"simple.yaml", templateString)
  20. }
  21. func writeFile(fileName string, data string) error {
  22. // 将字符串写入文件
  23. err := os.WriteFile(fileName, []byte(data), 0644)
  24. if err != nil {
  25. return err
  26. }
  27. return nil
  28. }
  29. // 只有单签的流程模板
  30. func buildSignsTemp() {
  31. flow := approve_former.NewFlow("signs",
  32. approve_former.NewSign("A"),
  33. approve_former.NewSign("B"),
  34. approve_former.NewSign("C"))
  35. templateString1, err := flow.Render(nil)
  36. if err != nil {
  37. panic(err)
  38. }
  39. _ = writeFile(dir+"signs.yaml", templateString1)
  40. }
  41. // 会签和或签
  42. func buildAndORTemp() {
  43. flow := approve_former.NewFlow("andor",
  44. approve_former.NewSign("A"),
  45. approve_former.NewAnd(
  46. approve_former.NewSign("B"), approve_former.NewSign("C"),
  47. ),
  48. approve_former.NewOr(
  49. approve_former.NewSign("D"), approve_former.NewSign("E"),
  50. ),
  51. approve_former.NewSign("F"),
  52. )
  53. templateString, err := flow.Render(nil)
  54. if err != nil {
  55. panic(err)
  56. }
  57. _ = writeFile(dir+"andor.yaml", templateString)
  58. }