Skip to content

Commit

Permalink
feat: add cloudrunner.PubsubHTTPHandler top-level method
Browse files Browse the repository at this point in the history
Make Pub/Sub HTTP handlers part of the main module interface.
  • Loading branch information
odsod committed Aug 6, 2021
1 parent f9f26b7 commit 68a0178
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cloudpubsub/httphandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
"google.golang.org/protobuf/types/known/timestamppb"
)

// NewHTTPHandler creates a new HTTP handler for Cloud Pub/Sub push messages.
// HTTPHandler creates a new HTTP handler for Cloud Pub/Sub push messages.
// See: https://cloud.google.com/pubsub/docs/push
func NewHTTPHandler(fn func(context.Context, *pubsub.PubsubMessage) error) http.Handler {
func HTTPHandler(fn func(context.Context, *pubsub.PubsubMessage) error) http.Handler {
return httpHandlerFn(fn)
}

Expand Down
2 changes: 1 addition & 1 deletion cloudpubsub/httphandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestNewHTTPHandler(t *testing.T) {
actualMessage = message
return nil
}
server := httptest.NewServer(NewHTTPHandler(fn))
server := httptest.NewServer(HTTPHandler(fn))
defer server.Close()
request, err := http.NewRequest(http.MethodPost, server.URL, strings.NewReader(example))
assert.NilError(t, err)
Expand Down
15 changes: 15 additions & 0 deletions pubsubhttphandler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cloudrunner

import (
"context"
"net/http"

"go.einride.tech/cloudrunner/cloudpubsub"
"google.golang.org/genproto/googleapis/pubsub/v1"
)

// PubsubHTTPHandler creates a new HTTP handler for Cloud Pub/Sub push messages.
// See: https://cloud.google.com/pubsub/docs/push
func PubsubHTTPHandler(fn func(context.Context, *pubsub.PubsubMessage) error) http.Handler {
return cloudpubsub.HTTPHandler(fn)
}

0 comments on commit 68a0178

Please sign in to comment.