Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: Mention setting function target env variable when starting dev server using ide #266

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

Open
gregorygaines wants to merge 5 commits into GoogleCloudPlatform:main
base: main
Choose a base branch
Loading
from gregorygaines:main

Conversation

@gregorygaines
Copy link

@gregorygaines gregorygaines commented Apr 6, 2025

When starting the functions framework from the Intellij 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)
	}
}

This PR adds commented code to the quickstart example mentioning that local servers started from IDE's require the function target env variable set to the function name.

@gregorygaines gregorygaines changed the title (削除) chore: Mention setting function target env variable when starting dev server (削除ここまで) (追記) chore: Mention setting function target env variable when starting dev server using ide (追記ここまで) Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /