英文:
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)
请注意函数名称的大小写差异:runUsers
与RunUsers
。
英文:
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
文件),请参考文档:
英文:
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:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论