template / ci-testing / files / postscript.go
Branch ci-testing · default branch · all branches
postscript.go
c62570e2 2022-09-23 Pavel Safronov | 1 | package main |
| 2 | ||
| 3 | import ( | |
763c260d 2022-10-06 Pavel Safronov | 4 | "fmt" |
c62570e2 2022-09-23 Pavel Safronov | 5 | "strings" |
| 6 | "text/template" | |
| 7 | ) | |
| 8 | ||
687d5626 2022-10-28 Pavel Safronov | 9 | func createPostScriptArrays( |
| 10 | profile Profile, | |
| 11 | postPatternData PostPatternData) ([]string, error) { | |
d1bc1307 2022-09-24 Pavel Safronov | 12 | array := make([]string, 0) |
c62570e2 2022-09-23 Pavel Safronov | 13 | |
4a7759db 2022-09-24 Pavel Safronov | 14 | if profile.PostScripts == nil || len(profile.PostScripts) == 0 { |
763c260d 2022-10-06 Pavel Safronov | 15 | return nil, fmt.Errorf("no post scripts specified") |
c62570e2 2022-09-23 Pavel Safronov | 16 | } |
| 17 | ||
d1bc1307 2022-09-24 Pavel Safronov | 18 | for _, postScriptPattern := range profile.PostScripts { |
1a02ef4e 2022-10-21 Pavel Safronov | 19 | template, err := template.New("postscript").Parse(string(postScriptPattern)) |
d1bc1307 2022-09-24 Pavel Safronov | 20 | if err != nil { |
| 21 | return nil, err | |
| 22 | } | |
c62570e2 2022-09-23 Pavel Safronov | 23 | |
d1bc1307 2022-09-24 Pavel Safronov | 24 | sb := new(strings.Builder) |
687d5626 2022-10-28 Pavel Safronov | 25 | err = template.Execute(sb, postPatternData) |
d1bc1307 2022-09-24 Pavel Safronov | 26 | if err != nil { |
| 27 | return nil, err | |
4a7759db 2022-09-24 Pavel Safronov | 28 | } |
d1bc1307 2022-09-24 Pavel Safronov | 29 | |
| 30 | postScript := sb.String() | |
| 31 | array = append(array, postScript) | |
c62570e2 2022-09-23 Pavel Safronov | 32 | } |
| 33 | ||
| 34 | return array, nil | |
| 35 | } |