Skip to content

Commit

Permalink
Improve readme examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Karol Stępniewski authored Jul 18, 2018
1 parent 783d5b3 commit 50e8811
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Package cloudevents provides primitives to work with CloudEvents specification:

Parsing Event from HTTP Request:
```go
import "github.com/dispatchframework/cloudevents-go-sdk"
// req is *http.Request
event, err := cloudEvents.FromHTTPRequest(req)
if err != nil {
Expand All @@ -16,14 +17,23 @@ Parsing Event from HTTP Request:

Creating a minimal CloudEvent in version 0.1:
```go
import "github.com/dispatchframework/cloudevents-go-sdk/v01"
import "github.com/dispatchframework/cloudevents-go-sdk/v01"
event := v01.Event{
EventType: "com.example.file.created",
Source: "/providers/Example.COM/storage/account#fileServices/default/{new-file}",
EventID: "ea35b24ede421",
}
```

Creating HTTP request from CloudEvent:
```
var req *http.Request
err := event.ToHTTPRequest(req)
if err != nil {
panic("Unable to marshal event into http Request: " + err.String())
}
```

The goal of this package is to provide support for all released versions of CloudEvents, ideally while maintaining
the same API. It will use semantic versioning with following rules:
* MAJOR version increments when backwards incompatible changes is introduced.
Expand All @@ -42,4 +52,4 @@ Existing projects that added support for CloudEvents in Go are listed below. It'
of using CloudEvents in Go-based project and design the SDK to support these patterns (where it makes sense).
- https://github.com/google/cloudevents-demo/tree/master/pkg/event
- https://github.com/vmware/dispatch/blob/master/pkg/events/cloudevent.go
- https://github.com/serverless/event-gateway/tree/master/event
- https://github.com/serverless/event-gateway/tree/master/event

0 comments on commit 50e8811

Please sign in to comment.