Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,32 @@ func main() {

## Send your first CDEvent as CloudEvent

Import the modules in your code

```golang
import cdevents "github.com/cdevents/sdk-go/pkg/api"
import cloudevents "github.com/cloudevents/sdk-go/v2"
```

To send a CDEvent as CloudEvent:

```golang
func main() {
// (...) set the event first
ce := cdevents.AsCloudEvent(event)
ce, err := cdevents.AsCloudEvent(event)

// Set send options
ctx := cloudevents.ContextWithTarget(context.Background(), "http://localhost:8080/")
ctx = cloudevents.WithEncodingBinary(ctx)

// Sent the CloudEvent
c, err := cloudevents.NewClientHTTP()
if err != nil {
log.Fatalf("failed to create client, %v", err)
}

// Send the CloudEvent
// c is a CloudEvent client
if result := c.Send(ctx, ce); cloudevents.IsUndelivered(result) {
if result := c.Send(ctx, *ce); cloudevents.IsUndelivered(result) {
log.Fatalf("failed to send, %v", result)
}
}
Expand Down