Skip to content
Merged
Changes from 2 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
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,31 @@ func main() {

## Send your first CDEvent as CloudEvent

Import the module in your code

```golang
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)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation seems off here


// 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