Skip to content

Commit e5b17be

Browse files
authored
Merge pull request #143 from enrichman/inject
Added `inject` function
2 parents f7255d4 + 7f22c8a commit e5b17be

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

pkg/functions/functions.go

+15-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ import (
2424
"bufio"
2525
"encoding/csv"
2626
"fmt"
27-
"github.com/google/uuid"
28-
"github.com/ugol/jr/pkg/constants"
29-
"github.com/ugol/jr/pkg/ctx"
30-
"golang.org/x/text/cases"
31-
"golang.org/x/text/language"
3227
"log"
3328
"math"
3429
"math/rand"
@@ -37,6 +32,12 @@ import (
3732
"strconv"
3833
"strings"
3934
"text/template"
35+
36+
"github.com/google/uuid"
37+
"github.com/ugol/jr/pkg/constants"
38+
"github.com/ugol/jr/pkg/ctx"
39+
"golang.org/x/text/cases"
40+
"golang.org/x/text/language"
4041
)
4142

4243
func FunctionsMap() template.FuncMap {
@@ -47,6 +48,8 @@ var Random = rand.New(rand.NewSource(0))
4748
var data = map[string][]string{}
4849
var fmap = map[string]interface{}{
4950

51+
"inject": Inject,
52+
5053
// text utilities
5154
"atoi": Atoi,
5255
"itoa": strconv.Itoa,
@@ -523,3 +526,10 @@ func InitCSV(csvpath string) {
523526
}
524527

525528
}
529+
530+
func Inject(perc float64, injected, orig string) string {
531+
if rand.Float64() < perc {
532+
return injected
533+
}
534+
return orig
535+
}

0 commit comments

Comments
 (0)