-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Allow registering multiple functions with one server for local testing. #143
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks for the major refactor! This makes all the code a lot cleaner now.
@@ -39,10 +39,6 @@ const ( | |||
fnErrorMessageStderrTmpl = "Function error: %v" | |||
) | |||
|
|||
var ( | |||
handler http.Handler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
funcframework/framework.go
Outdated
if err == nil { | ||
handler = server | ||
if err := registry.Default().RegisterHTTP(path, fn, registry.WithPath(path)); err != nil { | ||
return fmt.Errorf("failed to register function at path %s: %s", path, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] maybe include function target in the error message too? Also, prefer %q for strings instead of %s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function name is included so it should be fine. Changed %s to %q
funcframework/framework.go
Outdated
server, err := wrapHTTPFunction(path, fn) | ||
if err == nil { | ||
handler = server | ||
if err := registry.Default().RegisterHTTP(path, fn, registry.WithPath(path)); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, maybe just return registry.Default().RegisterHTTP
's result directly? Make the error message returned by that more detailed if it isn't detailed enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
internal/registry/registry.go
Outdated
EventFn interface{} // Optional: The user's Event function | ||
} | ||
|
||
// Option is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] unfinished comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks for catching this.
funcframework/framework.go
Outdated
server, err := wrapHTTPFunction(path, fn) | ||
if err == nil { | ||
handler = server | ||
if err := registry.Default().RegisterHTTP(path, fn, registry.WithPath(path)); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I kind of forgot these didn't have names... Maybe we should give it a readable name like fmt.Sprintf("function at path %q", path)
or something so that error messages that print the function name won't look as weird.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
if err := RegisterHTTPFunctionContext(context.Background(), "/", func(w http.ResponseWriter, r *http.Request) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we still want to have some test that mixes both the older RegisterHTTPFunctionContext and functions.HTTP
calls and makes sure things work as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
… local testing. (GoogleCloudPlatform#143)" This reverts commit 3cab285.
…testing (#154) * feat: Allow registering multiple functions with one server for local testing (restore PR #143) * feat: serve the last func that's not registered declaratively if no target is found * Store declaratively defined functions in map and others in array * update error message * Add test case that multiple options are specified * update registry reset func * change the implementation of registry reset func
There are two ways to test multiple functions within one server.
functions.HTTP()
) and rungo run cmd/main.go
without setting the env varFUNCTION_TARGET
. In this case, all registered functions will be served at "/{func_name}".funcframework.RegisterHTTPFunctionContext()
) and rungo run cmd/main.go
without setting the env varFUNCTION_TARGET
. In this case, the registered handlers will be served at the user defined path.Closes #109