Skip to content

Latest commit

 

History

History

211209-serverless

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

初次尝试serverless

参考文档

如何使用

依赖安装

go mod tidy

编译打包

GOOS=linux GOARCH=amd64 go build -o main main.go
zip main.zip main

最后将打包好的 main.zip 上传至 函数代码 中,进行 部署

初始下载的代码备份

package main

import (
    "context"
    "fmt"
    "github.com/tencentyun/scf-go-lib/cloudfunction"
)

type DefineEvent struct {
    // test event define
    Key1 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 Function
    cloudfunction.Start(hello)
}