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

http: Fixes for Gin http receiver sample #905

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 4 additions & 5 deletions samples/http/receiver-gin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ An example of a Gin webframework CloudEvents receiver with a [TektonEvent](https
Get dependencies
```shell
cd samples/
go get github.com/gin-gonic/gin
go get github.com/rs/zerolog/log
go get

```

Expand All @@ -18,11 +17,11 @@ Run the app
go run main.go
```

Test a CloudEvent
Send a CloudEvent
```shell
curl -v \
-H "Ce-Id: e7d95c20-6eb4-4614-946d-27b0ce41c7ff" \
-H "Ce-Source: /apis///namespaces/dimitar//clone-build-n4qhgl" \
-H "Ce-Source: /apis/namespaces/dimitar/clone-build-n4qhgl" \
Copy link
Member

Choose a reason for hiding this comment

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

You need to change this in the output below too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Source changed in the output as well.

-H "Ce-Subject: clone-build-n4qhgl" \
-H "Ce-Specversion: 1.0" \
-H "Ce-Type: dev.tekton.event.pipelinerun.started.v1" \
Expand All @@ -39,7 +38,7 @@ Logs output
Got an Event: Context Attributes,
specversion: 1.0
type: dev.tekton.event.pipelinerun.started.v1
source: /apis///namespaces/dimitar//clone-build-n4qhgl
source: /apis/namespaces/dimitar/clone-build-n4qhgl
subject: clone-build-n4qhgl
id: e7d95c20-6eb4-4614-946d-27b0ce41c7ff
datacontenttype: application/json
Expand Down
6 changes: 2 additions & 4 deletions samples/http/receiver-gin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/gin-gonic/gin"
)

func receiveTektonEvent(event cloudevents.Event) {
func receive(event cloudevents.Event) {
fmt.Printf("Got an Event: %s", event)
}

Expand All @@ -23,7 +23,6 @@ func healthz(c *gin.Context) {
}

func cloudEventsHandler() gin.HandlerFunc {

return func(c *gin.Context) {
p, err := cloudevents.NewHTTP()
if err != nil {
Expand All @@ -32,7 +31,7 @@ func cloudEventsHandler() gin.HandlerFunc {
Msg("Failed to create protocol")
}

ceh, err := cloudevents.NewHTTPReceiveHandler(c, p, receiveTektonEvent)
ceh, err := cloudevents.NewHTTPReceiveHandler(c, p, receive)
if err != nil {
log.Fatal().
Err(err).
Expand All @@ -44,7 +43,6 @@ func cloudEventsHandler() gin.HandlerFunc {
}

func main() {

r := gin.Default()
r.SetTrustedProxies(nil)

Expand Down