Skip to content

Commit 5232986

Browse files
authored
http: Fixes for Gin http receiver sample (#905)
Fixes for prematurely closed #842 PR. Applied all suggested code and doc changes.. Signed-off-by: Dimitar Georgievski <dgeorgievski@gmail.com>
1 parent 9970acc commit 5232986

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

samples/http/receiver-gin/README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ An example of a Gin webframework CloudEvents receiver with a [TektonEvent](https
88
Get dependencies
99
```shell
1010
cd samples/
11-
go get github.com/gin-gonic/gin
12-
go get github.com/rs/zerolog/log
11+
go get
1312

1413
```
1514

@@ -18,11 +17,11 @@ Run the app
1817
go run main.go
1918
```
2019

21-
Test a CloudEvent
20+
Send a CloudEvent
2221
```shell
2322
curl -v \
2423
-H "Ce-Id: e7d95c20-6eb4-4614-946d-27b0ce41c7ff" \
25-
-H "Ce-Source: /apis///namespaces/dimitar//clone-build-n4qhgl" \
24+
-H "Ce-Source: /apis/namespaces/dimitar/clone-build-n4qhgl" \
2625
-H "Ce-Subject: clone-build-n4qhgl" \
2726
-H "Ce-Specversion: 1.0" \
2827
-H "Ce-Type: dev.tekton.event.pipelinerun.started.v1" \
@@ -39,7 +38,7 @@ Logs output
3938
Got an Event: Context Attributes,
4039
specversion: 1.0
4140
type: dev.tekton.event.pipelinerun.started.v1
42-
source: /apis///namespaces/dimitar//clone-build-n4qhgl
41+
source: /apis/namespaces/dimitar/clone-build-n4qhgl
4342
subject: clone-build-n4qhgl
4443
id: e7d95c20-6eb4-4614-946d-27b0ce41c7ff
4544
datacontenttype: application/json

samples/http/receiver-gin/main.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/gin-gonic/gin"
1111
)
1212

13-
func receiveTektonEvent(event cloudevents.Event) {
13+
func receive(event cloudevents.Event) {
1414
fmt.Printf("Got an Event: %s", event)
1515
}
1616

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

2525
func cloudEventsHandler() gin.HandlerFunc {
26-
2726
return func(c *gin.Context) {
2827
p, err := cloudevents.NewHTTP()
2928
if err != nil {
@@ -32,7 +31,7 @@ func cloudEventsHandler() gin.HandlerFunc {
3231
Msg("Failed to create protocol")
3332
}
3433

35-
ceh, err := cloudevents.NewHTTPReceiveHandler(c, p, receiveTektonEvent)
34+
ceh, err := cloudevents.NewHTTPReceiveHandler(c, p, receive)
3635
if err != nil {
3736
log.Fatal().
3837
Err(err).
@@ -44,7 +43,6 @@ func cloudEventsHandler() gin.HandlerFunc {
4443
}
4544

4645
func main() {
47-
4846
r := gin.Default()
4947
r.SetTrustedProxies(nil)
5048

0 commit comments

Comments
 (0)