26 lines
625 B
Go
26 lines
625 B
Go
|
package strings
|
||
|
|
||
|
import (
|
||
|
"encoding/base64"
|
||
|
|
||
|
"github.com/zclconf/go-cty/cty"
|
||
|
"github.com/zclconf/go-cty/cty/function"
|
||
|
)
|
||
|
|
||
|
func Base64Encode() function.Function {
|
||
|
return function.New(&function.Spec{
|
||
|
Description: "Encode a string as base64",
|
||
|
Params: []function.Parameter{
|
||
|
{
|
||
|
Name: "input",
|
||
|
Description: "input string to be encoded as base64",
|
||
|
Type: cty.String,
|
||
|
},
|
||
|
},
|
||
|
Type: function.StaticReturnType(cty.String),
|
||
|
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
|
||
|
return cty.StringVal(base64.StdEncoding.EncodeToString([]byte(args[0].AsString()))), nil
|
||
|
},
|
||
|
})
|
||
|
}
|