Skip to content

Commit 842073e

Browse files
committed
Add "last"
1 parent 3de56f0 commit 842073e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

template.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"log"
1111
"os"
1212
"path/filepath"
13+
"reflect"
14+
"sort"
1315
"strings"
1416
"syscall"
1517
"text/template"
@@ -90,6 +92,11 @@ func marshalJson(input interface{}) (string,error) {
9092
return strings.TrimSuffix(buf.String(), "\n"), nil
9193
}
9294

95+
func arrayLast(input interface{}) interface{} {
96+
arr := reflect.ValueOf(input)
97+
return arr.Index(arr.Len() - 1).Interface()
98+
}
99+
93100
func generateFile(config Config, containers Context) bool {
94101
templatePath := config.Template
95102
tmpl, err := template.New(filepath.Base(templatePath)).Funcs(template.FuncMap{
@@ -102,6 +109,7 @@ func generateFile(config Config, containers Context) bool {
102109
"dict": dict,
103110
"sha1": hashSha1,
104111
"json": marshalJson,
112+
"last": arrayLast,
105113
}).ParseFiles(templatePath)
106114
if err != nil {
107115
log.Fatalf("unable to parse template: %s", err)

0 commit comments

Comments
 (0)