首页 > 解决方案 > Golang Serverless 离线

问题描述

我是无服务器框架的新手,我有一些问题:我有一个在无服务器框架上开发的带有 Go Lang 的 APIGateway,我正在尝试让无服务器离线工作。我已经安装了 serverless-offline 插件,当我运行 sls offline start 命令时,一切都按预期进行。

当我在浏览器中运行“获取”路由时,出现以下错误:

在此处输入图像描述

我在 serverless.yml 中的函数配置

functions:
      getOrders:
        # The handler property points to the file and module containing the code you want to run in your function.
        handler: cmd/api/getOrders
        memorySize: 128 # Memory Size available to function while running
        description: Get all orders and convert them.
        events:
          - http:
              path: orders
              method: get

我的处理程序:


func getAllOrders(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {

        orders := services.GetAllOrders()

        // Success HTTP response
        body, _ := json.Marshal(&models.ListOrdersResponse{
            Orders: orders,
        })

        return events.APIGatewayProxyResponse{
            Body:       string(body),
            StatusCode: 200,
        }, nil
    }

    func main() {
        lambda.Start(getAllOrders)
    }

我究竟做错了什么?

标签: goaws-api-gatewayserverless-frameworkserverless

解决方案


推荐阅读