-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: declarative function api (#48)
* init declarative functions Signed-off-by: Lize Cai <[email protected]> * add tests for declarative functions Signed-off-by: Lize Cai <[email protected]> * update unit tests Signed-off-by: Lize Cai <[email protected]> * update e2e files for declarative functions Signed-off-by: Lize Cai <[email protected]> * add default http pattern for existing single function register method Signed-off-by: Lize Cai <[email protected]> * fix declarative tests, update CMD in dockerfile Signed-off-by: Lize Cai <[email protected]>
- Loading branch information
Showing
43 changed files
with
1,670 additions
and
29 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# IDE | ||
.idea/ | ||
.vscode/ | ||
.vscode/ | ||
|
||
bin/ |
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,11 @@ | ||
package functions | ||
|
||
import ( | ||
"github.com/OpenFunction/functions-framework-go/internal/functions" | ||
) | ||
|
||
type FunctionOption = functions.FunctionOption | ||
|
||
var ( | ||
WithFunctionPath = functions.WithFunctionPath | ||
) |
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,37 @@ | ||
// Package functions provides a way to declaratively register functions | ||
// that can be used to handle incoming requests. | ||
package functions | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"net/http" | ||
|
||
ofctx "github.com/OpenFunction/functions-framework-go/context" | ||
"github.com/OpenFunction/functions-framework-go/internal/registry" | ||
cloudevents "github.com/cloudevents/sdk-go/v2" | ||
) | ||
|
||
// HTTP registers an HTTP function that becomes the function handler served | ||
// at "/" when environment variable `FUNCTION_TARGET=name` | ||
func HTTP(name string, fn func(http.ResponseWriter, *http.Request), options ...FunctionOption) { | ||
if err := registry.Default().RegisterHTTP(name, fn, options...); err != nil { | ||
log.Fatalf("failure to register function: %s", err) | ||
} | ||
} | ||
|
||
// CloudEvent registers a CloudEvent function that becomes the function handler | ||
// served at "/" when environment variable `FUNCTION_TARGET=name` | ||
func CloudEvent(name string, fn func(context.Context, cloudevents.Event) error, options ...FunctionOption) { | ||
if err := registry.Default().RegisterCloudEvent(name, fn, options...); err != nil { | ||
log.Fatalf("failure to register function: %s", err) | ||
} | ||
} | ||
|
||
// OpenFunction registers a OpenFunction function that becomes the function handler | ||
// served at "/" when environment variable `FUNCTION_TARGET=name` | ||
func OpenFunction(name string, fn func(ofctx.Context, []byte) (ofctx.Out, error), options ...FunctionOption) { | ||
if err := registry.Default().RegisterOpenFunction(name, fn, options...); err != nil { | ||
log.Fatalf("failure to register function: %s", err) | ||
} | ||
} |
Oops, something went wrong.