Merge pull request #148 from batazor/fix

Fix index helpers
This commit is contained in:
Manfred Touron 2019-12-04 11:52:42 +01:00 committed by GitHub
commit 066f210f39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -94,15 +94,15 @@ var ProtoHelpersFuncMap = template.FuncMap{
"trimstr": func(cutset, s string) string {
return strings.Trim(s, cutset)
},
"index": func(array interface{}, i int32) interface{} {
"index": func(array interface{}, i int) interface{} {
slice := reflect.ValueOf(array)
if slice.Kind() != reflect.Slice {
panic("Error in index(): given a non-slice type")
}
if i < 0 || int(i) >= slice.Len() {
if i < 0 || i >= slice.Len() {
panic("Error in index(): index out of bounds")
}
return slice.Index(int(i)).Interface()
return slice.Index(i).Interface()
},
"add": func(a int, b int) int {
return a + b