github.com/hashicorp/packer@v1.14.3/hcl2template/function/ends_with.go (about) 1 package function 2 3 import ( 4 "strings" 5 6 "github.com/zclconf/go-cty/cty" 7 "github.com/zclconf/go-cty/cty/function" 8 ) 9 10 // EndsWithFunc constructs a function that checks if a string ends with 11 // a specific suffix using strings.HasSuffix 12 var EndsWithFunc = function.New(&function.Spec{ 13 Params: []function.Parameter{ 14 { 15 Name: "str", 16 Type: cty.String, 17 }, 18 { 19 Name: "suffix", 20 Type: cty.String, 21 }, 22 }, 23 Type: function.StaticReturnType(cty.Bool), 24 RefineResult: refineNotNull, 25 Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { 26 str := args[0].AsString() 27 suffix := args[1].AsString() 28 29 return cty.BoolVal(strings.HasSuffix(str, suffix)), nil 30 }, 31 })