Skip to content

Commit

Permalink
adding mmh3 hashing support
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzack9999 committed Oct 15, 2020
1 parent ecf92dc commit 5305965
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions v2/pkg/generators/dsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"strings"

"github.com/Knetic/govaluate"
"github.com/reusee/mmh3"
)

var letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
Expand Down Expand Up @@ -135,6 +136,16 @@ func HelperFunctions() (functions map[string]govaluate.ExpressionFunction) {
return hex.EncodeToString(h.Sum(nil)), nil
}

functions["mmh3"] = func(args ...interface{}) (interface{}, error) {
h := mmh3.New128()
_, err := h.Write([]byte(args[0].(string)))
if err != nil {
return nil, err
}

return hex.EncodeToString(h.Sum(nil)), nil
}

// search
functions["contains"] = func(args ...interface{}) (interface{}, error) {
return strings.Contains(args[0].(string), args[1].(string)), nil
Expand Down

0 comments on commit 5305965

Please sign in to comment.