-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: missing error message when return HTTPResult (#785)
* fix: missing error message when return HTTPResult Signed-off-by: wenfeng <[email protected]> * fmt: goimport Signed-off-by: wenfeng <[email protected]> * update according to reviewer's advice Signed-off-by: wenfeng <[email protected]>
- Loading branch information
1 parent
14755d1
commit b7b2232
Showing
4 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
Copyright 2022 The CloudEvents Authors | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
|
||
cloudevents "github.com/cloudevents/sdk-go/v2" | ||
) | ||
|
||
func main() { | ||
ctx := context.Background() | ||
p, err := cloudevents.NewHTTP() | ||
if err != nil { | ||
log.Fatalf("failed to create protocol: %s", err.Error()) | ||
} | ||
|
||
c, err := cloudevents.NewClient(p) | ||
if err != nil { | ||
log.Fatalf("failed to create client, %v", err) | ||
} | ||
|
||
log.Printf("will listen on :8080\n") | ||
log.Fatalf("failed to start receiver: %s", c.StartReceiver(ctx, receive)) | ||
} | ||
|
||
func receive(ctx context.Context, event cloudevents.Event) cloudevents.Result { | ||
fmt.Printf("%s", event) | ||
if event.Type() != "com.cloudevents.sample.sent" { | ||
return cloudevents.NewHTTPResult(http.StatusBadRequest, "invalid type of %s", event.Type()) | ||
} | ||
return cloudevents.NewHTTPResult(http.StatusOK, "") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters