You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Docs seem to indicate adding a user defined function is available and supported but I can't get this to work: (lifted from the README)
package main
import (
"fmt""os""strings"
cesql "github.com/cloudevents/sdk-go/sql/v2"
cefn "github.com/cloudevents/sdk-go/sql/v2/function"
cesqlparser "github.com/cloudevents/sdk-go/sql/v2/parser"
ceruntime "github.com/cloudevents/sdk-go/sql/v2/runtime"
cloudevents "github.com/cloudevents/sdk-go/v2"
)
funcmain() {
// Create a test eventevent:=cloudevents.NewEvent()
event.SetID("aaaa-bbbb-dddd")
event.SetSource("https://my-source")
event.SetType("dev.tekton.event")
// Create and add a new user defined functionvarHasPrefixFunction cesql.Function=cefn.NewFunction(
"HASPREFIX",
[]cesql.Type{cesql.StringType, cesql.StringType},
nil,
func(event cloudevents.Event, i []interface{}) (interface{}, error) {
str:=i[0].(string)
prefix:=i[1].(string)
returnstrings.HasPrefix(str, prefix), nil
},
)
err:=ceruntime.AddFunction(HasPrefixFunction)
// parse the expressionexpression, err:=cesqlparser.Parse("HASPREFIX(type, 'dev.tekton.event')")
iferr!=nil {
fmt.Println("parser err: ", err)
os.Exit(1)
}
// Evalute the expression with the test eventres, err:=expression.Evaluate(event)
ifres.(bool) {
fmt.Println("Event type has the prefix")
} else {
fmt.Println("Event type doesn't have the prefix")
}
}
Referencing v2.15.2 for the sdk. Maybe I am missing something obvious, thanks!
The text was updated successfully, but these errors were encountered:
Docs seem to indicate adding a user defined function is available and supported but I can't get this to work: (lifted from the README)
Referencing v2.15.2 for the sdk. Maybe I am missing something obvious, thanks!
The text was updated successfully, but these errors were encountered: