Skip to content

Commit

Permalink
fix: add simple add function for templates
Browse files Browse the repository at this point in the history
  • Loading branch information
believer committed Sep 29, 2023
1 parent a70d290 commit 133a74f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ func SetupAndRunApp() error {
// Add custom functions to the template engine
engine.AddFunc("StringsJoin", strings.Join)

// Simple add function
engine.AddFunc(
"add", func(x, y int) int {
return x + y
},
)

// Add possibility to send a map to the template
engine.AddFunc("map", func(pairs ...any) (map[string]any, error) {
if len(pairs)%2 != 0 {
return nil, errors.New("misaligned map")
Expand Down

0 comments on commit 133a74f

Please sign in to comment.