-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move declarative function API into
functions
package (#99)
This separates the encouraged, declarative function signature API away from the `funcframework` package, which should primarily be intended only for local testing going forward. Also, refactor some of the internal/registry implementation so it's more obvious that `functions` package and `funcframework` package are sharing the same registry.
- Loading branch information
Showing
6 changed files
with
80 additions
and
51 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package functions | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"net/http" | ||
|
||
"github.com/GoogleCloudPlatform/functions-framework-go/internal/registry" | ||
cloudevents "github.com/cloudevents/sdk-go/v2" | ||
) | ||
|
||
// Declaratively registers a HTTP function. | ||
func HTTP(name string, fn func(http.ResponseWriter, *http.Request)) { | ||
if err := registry.Default().RegisterHTTP(name, fn); err != nil { | ||
log.Fatalf("failure to register function: %s", err) | ||
} | ||
} | ||
|
||
// Declaratively registers a CloudEvent function. | ||
func CloudEvent(name string, fn func(context.Context, cloudevents.Event) error) { | ||
if err := registry.Default().RegisterCloudEvent(name, fn); err != nil { | ||
log.Fatalf("failure to register function: %s", err) | ||
} | ||
} |
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