main.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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("技术总监"),
  33. approve_former.NewSign("研发总监"),
  34. approve_former.NewSign("人事总监"))
  35. templateString, err := flow.Render(nil)
  36. if err != nil {
  37. panic(err)
  38. }
  39. _ = writeFile(dir+"signs.yaml", templateString)
  40. flow1 := approve_former.NewFlow("signs",
  41. approve_former.NewSign("A"),
  42. approve_former.NewSign("B"),
  43. approve_former.NewSign("C"))
  44. templateString1, err := flow1.Render(nil)
  45. if err != nil {
  46. panic(err)
  47. }
  48. _ = writeFile(dir+"signs1.yaml", templateString1)
  49. }
  50. // 会签和或签
  51. func buildAndORTemp() {
  52. flow := approve_former.NewFlow("andor",
  53. approve_former.NewSign("A"),
  54. approve_former.NewAnd(
  55. approve_former.NewSign("B"), approve_former.NewSign("C"),
  56. ),
  57. approve_former.NewOr(
  58. approve_former.NewSign("D"), approve_former.NewSign("E"),
  59. ),
  60. approve_former.NewSign("F"),
  61. )
  62. templateString, err := flow.Render(nil)
  63. if err != nil {
  64. panic(err)
  65. }
  66. _ = writeFile(dir+"andor.yaml", templateString)
  67. }