Google Cloud Function – 在Golang中找不到匹配的函数名称。

huangapple go评论83阅读模式
英文:

Google cloud Function - Golag no matching function found with name

问题

我正在尝试通过GitLab CI在GCP上运行我的函数,但是返回以下错误:

Function failed to start: no matching function found with name: "RunUsers"

路径:test/function.go

文件名:"function.go"

部署命令:

gcloud functions deploy test  
        --runtime=go116
        --entry-point=RunUsers
        --region=us-east1
        --source=.
        --trigger-http
package function

import (
	"io"
	"net/http"

	"github.com/GoogleCloudPlatform/functions-framework-go/functions"

	_ "github.com/GoogleCloudPlatform/functions-framework-go/funcframework"
)

func init() {
	functions.HTTP("RunUsers", RunUsers)
}

func RunUsers(w http.ResponseWriter, r *http.Request) {
	io.WriteString(w, "OK")
}

我应该在.gcloudignore文件中删除.mod吗?

.gcloudignore文件内容如下:

# This file specifies files that are *not* uploaded to Google Cloud
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).
#
# For more information, run:
#   $ gcloud topic gcloudignore
#
.gcloudignore
# If you would like to upload your .git directory, .gitignore file or files
# from your .gitignore file, remove the corresponding line
# below:
.git
.gitignore

tests/
README.md
Makefile
env/
*.json
sonar-project.properties
.gitlab-ci.yml
cmd/
*.mod

有人遇到过这个问题吗?

英文:

I'm trying to run my function on GCP via gitlab CI, but it returns the following error:

Function failed to start: no matching function found with name: "RunUsers"

path: test/function.go

file name "function.go"

deploy

gcloud functions deploy test  
        --runtime=go116
        --entry-point=RunUsers
        --region=us-east1
        --source=.
        --trigger-http
package function

import (
	"io"
	"net/http"

	"github.com/GoogleCloudPlatform/functions-framework-go/functions"

	_ "github.com/GoogleCloudPlatform/functions-framework-go/funcframework"
)

func init() {
	functions.HTTP("RunUsers", RunUsers)
}

func RunUsers(w http.ResponseWriter, r *http.Request) {
	io.WriteString(w, "OK")
}

Should I remove .mod in
.gcloudignore file?

gcloudignore:

# This file specifies files that are *not* uploaded to Google Cloud
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).
#
# For more information, run:
#   $ gcloud topic gcloudignore
#
.gcloudignore
# If you would like to upload your .git directory, .gitignore file or files
# from your .gitignore file, remove the corresponding line
# below:
.git
.gitignore

tests/
README.md
Makefile
env/
*.json
sonar-project.properties
.gitlab-ci.yml
cmd/
*.mod

Has anyone gone through this problem?

答案1

得分: 1

你正在指定入口点为:

--entry-point=RunUsers

函数声明如下:

func runUsers(w http.ResponseWriter, r *http.Request)

请注意函数名称的大小写差异:runUsersRunUsers

英文:

You are specifying the entrypoint as:

--entry-point=RunUsers

The function declaration is:

func runUsers(w http.ResponseWriter, r *http.Request)

Notice the difference in case for the function names: runUsers versus RunUsers.

答案2

得分: 0

在部署过程中出现了问题,代码是正确的,函数也在正常工作。

英文:

The problem occurred in the deploy, the code in was correct and the function working

答案3

得分: 0

在尝试在本地运行代码时,我遇到了相同的错误:

Serving function: "Execute"2023/02/06 11:57:36 funcframework.Start: no matching function found with name: "Execute"

解决方案需要在我的代码中包含一个 func init()(以及 cmd/main.go 文件),请参考文档:

https://github.com/GoogleCloudPlatform/functions-framework-go#quickstart-hello-world-on-your-local-machine

英文:

When trying to run the code locally I encountered the same error:

Serving function: "Execute"2023/02/06 11:57:36 funcframework.Start: no matching function found with name: "Execute"

The solution required including a func init() in my code (along with the cmd/main.go file), see documentation:

https://github.com/GoogleCloudPlatform/functions-framework-go#quickstart-hello-world-on-your-local-machine

huangapple
  • 本文由 发表于 2022年9月7日 04:17:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/73627359.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定