Skip to content

Commit

Permalink
Ported sendevent to sdk-go v2 (#3206)
Browse files Browse the repository at this point in the history
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
  • Loading branch information
slinkydeveloper authored May 26, 2020
1 parent 3d65f33 commit a00ee26
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions cmd/sendevent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"log"
"os"

cloudevents "github.com/cloudevents/sdk-go"
cloudevents "github.com/cloudevents/sdk-go/v2"

"knative.dev/eventing/pkg/utils"
)
Expand Down Expand Up @@ -64,10 +64,7 @@ func main() {
source = fmt.Sprintf("http://%s", utils.GetClusterDomainName())
}

t, err := cloudevents.NewHTTPTransport(
cloudevents.WithTarget(target),
cloudevents.WithBinaryEncoding(),
)
t, err := cloudevents.NewHTTP(cloudevents.WithTarget(target))
if err != nil {
log.Printf("failed to create transport, %v", err)
os.Exit(1)
Expand All @@ -87,13 +84,13 @@ func main() {
}
event.SetType(eventType)
event.SetSource(source)
if err := event.SetData(untyped); err != nil {
if err := event.SetData(cloudevents.ApplicationJSON, untyped); err != nil {
log.Printf("failed to set data, %v", err)
os.Exit(1)
}

if _, resp, err := c.Send(context.Background(), event); err != nil {
fmt.Printf("Failed to send event to %s: %s\n", target, err)
if resp, res := c.Request(context.Background(), event); !cloudevents.IsACK(res) {
fmt.Printf("Failed to send event to %s: %s\n", target, res.Error())
os.Exit(1)
} else if resp != nil {
fmt.Printf("Got response from %s\n%s\n", target, resp)
Expand Down

0 comments on commit a00ee26

Please sign in to comment.