Skip to content

Commit

Permalink
Release v0.16.0-megalithic.2
Browse files Browse the repository at this point in the history
  • Loading branch information
drauschenbach committed Jun 24, 2020
1 parent a772b96 commit bba952a
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
### v0.16.0-megalithic.1
### [v0.16.0-megalithic.2] - 2020-06-24

* Document arithmetic funcs from [#824](https://github.com/kelseyhightower/confd/pull/824)
* Add loop and loop1to to template_funcs from [#363](https://github.com/kelseyhightower/confd/pull/363)

### [v0.16.0-megalithic.1] - 2020-06-23

Build with Go 1.13 to add support for Go Template variable replacement.

Expand Down
58 changes: 58 additions & 0 deletions docs/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,64 @@ Alias for the [strconv.Atoi](https://golang.org/pkg/strconv/#Atoi) function.
{{seq 1 (atoi (getv "/count"))}}
```

### add

Add two integers.

```
{{$five := add 1 4}}
```

### sub

Subtract two integers.

```
{{$four := sub 10 6}}
```

### mul

Multiplicate two integers.

```
{{$six := mul 3 2}}
```

### div

Divide two integers.

```
{{$two := sub 6 3}}
```

### mod

Calculate modulus of two integers.

```
{{$three := mod 8 5}}
```

### loop

Takes two integers and generates the number of integers given by the first integer starting with the second integer.

```
# Generates [5,6,7]
{{loop 3 5}}
```

### loop1to

Generates integers from 1 to the given integer.

```
# Generates [1,2,3,4,5]
{{loop1to 5}}
```

## Example Usage

```Bash
Expand Down
18 changes: 18 additions & 0 deletions resource/template/template_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ import (
"github.com/kelseyhightower/memkv"
)

// loop take the number of elements to generate as well as the starting element. So loop(3, 5) will generate [5,6,7]
// It's helpful as it allow you to write templates like:
// {{range $index, $val := loop1to 2}}
// cpu-map {{ $val }} {{ $index }}
// {{end}}
// =>
// cpu-map 1 0
// cpu-map 2 1
func loop(n, s int) (arr []int) {
arr = make([]int, n)
for i := 0; i < n; i++ {
arr[i] = i + s
}
return
}

func newFuncMap() map[string]interface{} {
m := make(map[string]interface{})
m["base"] = path.Base
Expand Down Expand Up @@ -49,6 +65,8 @@ func newFuncMap() map[string]interface{} {
m["div"] = func(a, b int) int { return a / b }
m["mod"] = func(a, b int) int { return a % b }
m["mul"] = func(a, b int) int { return a * b }
m["loop"] = loop
m["loop1to"] = func(n int) []int { return loop(n, 1) }
m["seq"] = Seq
m["atoi"] = strconv.Atoi
return m
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package main

const Version = "0.16.0-megalithic.1"
const Version = "0.16.0-megalithic.2"

// We want to replace this variable at build time with "-ldflags -X main.GitSHA=xxx", where const is not supported.
var GitSHA = ""

0 comments on commit bba952a

Please sign in to comment.