Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update error in example in the README.md for cdevents.AsCloudEvent(event) #32

Closed
bradmccoydev opened this issue Nov 3, 2022 · 2 comments

Comments

@bradmccoydev
Copy link
Member

In the readme file the example of sending the event as a cloudevent is wrong as it cannot initialize 1 variables with 2 values. It is missing the reference to err.

Current:

ce := cdevents.AsCloudEvent(event)

Should be:

ce, err := cdevents.AsCloudEvent(event)

as per pkg/api/bindings.go line 153

// AsCloudEvent renders a CDEvent as a CloudEvent
func AsCloudEvent(event CDEventReader) (*cloudevents.Event, error) {
	if event == nil {
		return nil, fmt.Errorf("nil CDEvent cannot be rendered as CloudEvent")
	}
	// Validate the event
	err := Validate(event)
	if err != nil {
		return nil, fmt.Errorf("cannot validate CDEvent %v", err)
	}
	ce := cloudevents.NewEvent()
	ce.SetSource(event.GetSource())
	ce.SetSubject(event.GetSubjectId())
	ce.SetType(event.GetType().String())
	err = ce.SetData(cloudevents.ApplicationJSON, event)
	return &ce, err
}
@bradmccoydev bradmccoydev changed the title chore: Update error in example in the README.md for cdevents.AsCloudEvent(event) Update error in example in the README.md for cdevents.AsCloudEvent(event) Nov 3, 2022
@bradmccoydev
Copy link
Member Author

PR raised in #33

@bradmccoydev
Copy link
Member Author

Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant