产品动态
产品公告
package mainimport ("context""fmt""github.com/tencentyun/scf-go-lib/cloudfunction")type DefineEvent struct {// test event defineKey1 string `json:"key1"`Key2 string `json:"key2"`}func hello(ctx context.Context, event DefineEvent) (string, error) {fmt.Println("key1:", event.Key1)fmt.Println("key2:", event.Key2)return fmt.Sprintf("Hello %s!", event.Key1), nil}func main() {// Make the handler available for Remote Procedure Call by Cloud Functioncloudfunction.Start(hello)}
github.com/tencentyun/scf-go-lib/cloudfunction 库,在编译打包之前,执行 go get github.com/tencentyun/scf-go-lib/cloudfunction。encoding/json 标准库,可以进行 Marshal、Unmarshal。main,此处 main 表示执行的入口文件为编译后的 main 二进制文件。import "github.com/tencentyun/scf-go-lib/cloudfunction",可以在 main 函数中使用包内的 Start 函数。func hello()func hello(ctx context.Context)func hello(event DefineEvent)func hello(ctx context.Context, event DefineEvent)
encoding/json 标准库,可以进行 Marshal、Unmarshal 操作,否则在送入入参时会因为异常而出错。import "github.com/tencentyun/scf-go-lib/events" 来直接使用。如果使用过程中发现问题,可以通过 提交 issue 或 提交工单 解决。func hello()()func hello()(error)func hello()(string, error)
encoding/json 标准库,可以进行 Marshal、Unmarshal 操作,否则在返回至外部接口时会因为异常转换而出错。文档反馈