刚创建了一个官方的示例,直接下载下来的代码引入的是 aliyun/serverless/的:
import ( “context” “fmt” “io” “net/http”
"aliyun/serverless/fc-runtime-go-sdk/fc"
"aliyun/serverless/fc-runtime-go-sdk/fccontext"
)
然后直接运行这个代码是会报下面这个错误:
http_demo.go:11:2: cannot find package “aliyun/serverless/fc-runtime-go-sdk/fc” in any of: /usr/local/opt/go/libexec/src/aliyun/serverless/fc-runtime-go-sdk/fc (from $GOROOT) /Users/garveycalvin/go/src/aliyun/serverless/fc-runtime-go-sdk/fc (from $GOPATH) http_demo.go:12:2: cannot find package “aliyun/serverless/fc-runtime-go-sdk/fccontext” in any of: /usr/local/opt/go/libexec/src/aliyun/serverless/fc-runtime-go-sdk/fccontext (from $GOROOT) /Users/garveycalvin/go/src/aliyun/serverless/fc-runtime-go-sdk/fccontext (from $GOPATH)
换成是 github.com/aliyun 的就会报这个错误:
import ( “context” “fmt” “io” “net/http”
"github.com/aliyun/fc-runtime-go-sdk/fc"
"github.com/aliyun/fc-runtime-go-sdk/fccontext"
)
/usr/local/opt/go/libexec/bin/go build -o /Users/garveycalvin/Library/Caches/JetBrains/GoLand2023.1/tmp/GoLand/___go_build_http_demo_go /Users/garveycalvin/go/test3/SuccessDiary/test3/http_demo.go #gosetup /Users/garveycalvin/Library/Caches/JetBrains/GoLand2023.1/tmp/GoLand/___go_build_http_demo_go 2023/03/22 12:14:32.352451 expected ali FC environment variables [FC_RUNTIME_API] are not defined
Process finished with the exit code 1
我应该怎样做才能在本地调试函数计算fc代码呢?
函数计算如何本地调试函数,
如果你的Runtime不是Custom Runtime,而是函数计算内置语言,例如Node.js、Python等,推荐使用Serverless Devs工具的本地调用方式进行调试。具体操作,请参见Local命令。
如果你的Runtime是Custom Runtime,可以按照正常的开发习惯发起一个Server代码调试流程。 需要注意的是:针对Custom Runtime,s local invoke命令能正常发起函数本地执行,但不支持断点调试。
go目前好像还不能端云联调。
此答案来自钉钉群“阿里函数计算官网客户”
Flow 提供了阿里云函数计算(FC)发布能力,支持对已有的函数进行发布。支持使用 OSS 中保存的函数 zip 包发布到阿里云函数计算。函数计算(Function Compute)是一个事件驱动的全托管 Serverless 计算服务。您无需管理服务器等基础设置,只需编写代码并上传。函数计算会为您准备好计算资源,并以弹性、可靠的方式运行您的代码:https://help.aliyun.com/document_detail/160078.html?scm=20140722.184.2.173#section-bgk-d8k-6ok
函数计算如何本地调试函数,
如果你的Runtime不是Custom Runtime,而是函数计算内置语言,例如Node.js、Python等,推荐使用Serverless Devs工具的本地调用方式进行调试。具体操作,请参见Local命令。
如果你的Runtime是Custom Runtime,可以按照正常的开发习惯发起一个Server代码调试流程。 需要注意的是:针对Custom Runtime,s local invoke命令能正常发起函数本地执行,但不支持断点调试。