Skip to content

Commit

Permalink
http: Fixes for Gin http receiver sample
Browse files Browse the repository at this point in the history
Fixes for prematurely closed cloudevents#842 PR. Applied all suggested code and doc
changes..
  • Loading branch information
dgeorgievski committed Jun 2, 2023
1 parent 9970acc commit 3504c71
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
7 changes: 3 additions & 4 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" \
-H "Ce-Subject: clone-build-n4qhgl" \
-H "Ce-Specversion: 1.0" \
-H "Ce-Type: dev.tekton.event.pipelinerun.started.v1" \
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

0 comments on commit 3504c71

Please sign in to comment.