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