-
Notifications
You must be signed in to change notification settings - Fork 62
Open
Labels
P3Low PriorityLow PrioritydocumentationImprovements or additions to documentationImprovements or additions to documentation
Description
I work with alot of IDE tools and when I start the functions framework from my ide, the application throws 404 on each request:
function.go
package function
import (
"fmt"
"net/http"
"github.com/GoogleCloudPlatform/functions-framework-go/functions"
)
func init() {
functions.HTTP("HelloWorld", helloWorld)
}
// helloWorld writes "Hello, World!" to the HTTP response.
func helloWorld(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Hello, World!")
}
cmd/main.go
package main
import (
"log"
// Blank-import the function package so the init() runs
"github.com/GoogleCloudPlatform/functions-framework-go/funcframework"
_ "example.com/hello"
)
func main() {
if err := funcframework.StartHostPort("127.0.0.1", "8082"); err != nil {
log.Fatalf("funcframework.StartHostPort: %v\n", err)
}
}
When starting a go app from an IDE, either set the "FUNCTION_TARGET" env variable or set manually in code:
package main
import (
"log"
// Blank-import the function package so the init() runs
"github.com/GoogleCloudPlatform/functions-framework-go/funcframework"
_ "example.com/hello"
)
func main() {
err := os.Setenv("FUNCTION_TARGET", "HelloWorld")
if err != nil {
log.Fatalf("failed to set FUNCTION_TARGET: %v", err)
}
if err := funcframework.StartHostPort("127.0.0.1", "8082"); err != nil {
log.Fatalf("funcframework.StartHostPort: %v\n", err)
}
}
I think we can resolve some confusion if we mention this in the quickstart docs, I created a PR #266 to include this comment.
Metadata
Metadata
Assignees
Labels
P3Low PriorityLow PrioritydocumentationImprovements or additions to documentationImprovements or additions to documentation