mirror of
https://github.com/hashicorp/packer.git
synced 2026-06-15 11:38:59 -04:00
33 lines
564 B
Go
33 lines
564 B
Go
|
|
package function
|
||
|
|
|
||
|
|
import (
|
||
|
|
"strings"
|
||
|
|
|
||
|
|
"github.com/zclconf/go-cty/cty"
|
||
|
|
"github.com/zclconf/go-cty/cty/function"
|
||
|
|
)
|
||
|
|
|
||
|
|
var StrContains = function.New(&function.Spec{
|
||
|
|
Params: []function.Parameter{
|
||
|
|
{
|
||
|
|
Name: "str",
|
||
|
|
Type: cty.String,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
Name: "substr",
|
||
|
|
Type: cty.String,
|
||
|
|
},
|
||
|
|
},
|
||
|
|
Type: function.StaticReturnType(cty.Bool),
|
||
|
|
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
|
||
|
|
str := args[0].AsString()
|
||
|
|
substr := args[1].AsString()
|
||
|
|
|
||
|
|
if strings.Contains(str, substr) {
|
||
|
|
return cty.True, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
return cty.False, nil
|
||
|
|
},
|
||
|
|
})
|